Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help me fix this Respawn script?

I have this in a Server Script:

game.Players.PlayerAdded:connect(function(player) 
    local died = true
    repeat wait() until player.Character 
    local Humanoid = player.Character:WaitForChild("Humanoid")
	Humanoid.Died:connect(function() 
        died = true -- If player died, change variable 
    end) 

    player.CharacterAdded:connect(function(character) 
        if died then -- If the player died then 
            print(player.Name .. " has been reapwned!") 
		
            died = false
        else -- If the player didn't die then 
            print(player.Name .. " has been loaded!") 
            died = false 
        end 
    end) 
end) 

Since my game features the ability to refresh your character with :LoadCharacter, this code is supposed to distinguish between loading your character and actually dieing. However when I test it, after death the script distinguishes the respawn as a "load". I think it's because the :Died event is taking to long to activate, but I'm not too sure. Any ideas?

3 comments

2

You could try checking if the health equals 0 instead of using the Died event.

0

Does anything come out in the output, like errors or any prints?

0

No errors. I'll try setting the Health to 0 and see where that gets me.

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.