Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help me fix this Respawn script?

Asked by
Zerio920 285 Moderation Voter
10 years ago

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?

2
You could try checking if the health equals 0 instead of using the Died event. Perci1 4988 — 10y
0
Does anything come out in the output, like errors or any prints? bobafett3544 198 — 10y
0
No errors. I'll try setting the Health to 0 and see where that gets me. Zerio920 285 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

Do what Perci1 said do health equals 0.

Ad

Answer this question