How to make a script wait until the player it kills respawns

I’m making a custom health script, and I have a loop constantly running that manages a gui for the health bar. When the loop detects the players health value as 0 it kills them, then sets the value back to its maximum.
My problem is that I want the health to be reset when the player respawns instead of right after dying, and I don’t know how to make the script wait until that happens.

while true do
	
	if Player.Health.Value > 0 then
		--Scale the health bar gui to the health value
	else
		Player.Character:BreakJoints()
		--Something to delay until the player respawns
		Player.Health.Value = 100
	end
wait()
end

What would I do to delay the script for the same time as the players respawn? Using something like wait() would be inconsistent with lag.

You could use a

Player.CharacterAdded:Wait()

to wait for the character to load in and then you can set their health.

Player:CharacterAdded:Wait() just causes an error, but Player.CharacterAdded:Wait() does work. I also just realized while fiddling with your suggestion that the script runs restarts on respawn, so I just needed to set the players health before the loop starts to get it to work.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.