Hi. Recently I made a loop that is supposed to stop when a player dies. The problem is that it doesn't. Here is my code:
while plr.Character.Humanoid.Health >0 do
wait(20)
print'ree'
plr.Character.Humanoid.Health = plr.Character.Humanoid.Health + 5
end
Note: I turned off player health regen so I could make this instead.
As you can see, I made a system where health regens every 20 seconds by 5, but this does not end when the player dies. How could I fix this?

4 comments
i should automatically stop and error when the characters descendants don't exist
it*
All you have to do is use the function break.
do you do a return end if the player's health is 0? I tried it but it isn't working