I have a script inside the StarterGui that is supposed to fire whenever a player dies. Here's the script (the script isn't a localscript):
local player = script.Parent.Parent
repeat wait() until player.Character
repeat wait() until player.Character:findFirstChild("Humanoid")
player.Character.Humanoid.Changed:connect(function()
repeat wait() until player.Character
if player.Character.Humanoid.Health <= 0 then
print'dead'
wait(4)
player:LoadCharacter()
repeat wait() until player.Character
player.Character.Torso.CFrame = CFrame.new(game.Workspace.teleportPlayerHere.Position)
player.Character.ForceField:Destroy()
end
end)
The script works fine the first time a player dies, but it doesn't do anything the second time. There isn't anything in the output when the player dies the second time. Any help?

3 comments
This is fine but it doesn't explain why my script works only once.
Well, once you respawn the character, the GUI resets itself, so the script goes back to the beginning. I'm surprised it even worked the first time
I forgot to mention that I set the PlayerGui's hidden property that resets the GUIs to false, so it doesn't reset when the player resets.