Minecraft – Detect when a player respawns, Possible?

minecraft-commandsminecraft-java-edition

I have tried and tried but I can't find any solution that fits 1.13. Is there anyway possible to detect when a player respawns. My goal is to remove all the effects on a player when they respawns. But I'm just too bad. I have tried some commands from videos but they are just to outdated

I have tried THIS Video and it uses an old trick so it was no use. I tried to find a player respawn scoreboard with no luck. And finally I tried this:

(In a repeating command block, always acitve)

/execute as @a[scores={M_Death=1}] run effect clear @a[scores={M_Death=1}]

(In a chain command block, condential, always active)

/scoreboard players reset @a[scores={M_Death=1}] M_Death

Any idea anyone?

Best Answer

Assuming you have a scoreboard that tracks deaths, you only need to find players that are alive and have a score of 1 or more on that scoreboard. The @a target selector targets all players, regardless of whether they are alive or dead. The @e[type=player] target selector only targets alive players. This is the result:

/effect clear @e[type=player,scores={deaths=1..}]
/scoreboard players reset @e[type=player,scores={deaths=1..}] deaths