I'm working on a skript where when a player dies, they would "freeze" for to seconds. I don't know why this isn't working, please tell me if you have any suggestions of fixing this, thanks.
code_language.skript:
on damage of player:
if damage > victim's health:
cancel event
send victim title "&cYOU DIED!" with subtitle "&7Respawning in 5 seconds§7!" for 5 seconds
set victim's gamemode to spectator
set {_location} to location of victim
set {_x} to x-coords of victim
set {_z} to z-coords of victim
loop 1000 times:
set {_x-check} to x-coords of victim
set {_z-check} to z-coords of victim
if {_x-check} isn't {_x}:
teleport victim to {_location}
if {_z-check} isn't {_z}:
teleport victim to {_location}
wait 5 seconds
set victim's gamemode to survival
set victim's health to 10