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

How can I fix this Death script?

Asked by
Zerio920 285 Moderation Voter
9 years ago

This is a server script:

game.Players.PlayerAdded:connect(function(player) 
local died = false 
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 resurrected!") 
died = false 

else -- If the player didn't die then 
print(player.Name .. " has been refreshed!") 
end 
end) 
end) 

It's meant to differentiate between when a player dies (respawns) and when a player reloads their character (refreshes) with :LoadCharacter (which is not dieing). However when a player dies it incorrectly reads "player has been refreshed" rather than "player has been respawned". How can I fix this?

1 answer

Log in to vote
-1
Answered by
Relatch 550 Moderation Voter
9 years ago
game.Players.PlayerAdded:connect(function(player) 
    local died = false 
    repeat wait() until player.Character 
    local Humanoid = player.Character:WaitForChild("Humanoid")
    Humanoid.Died:connect(function() 
        died = true -- If player died, change variable 
    end)
end) 

player.CharacterAdded:connect(function(character) 
    if died then -- If the player died then 
        print(player.Name .. " has been resurrected!") 
        died = false
    elseif died == false then
        print(player.Name .. " has been refreshed!") 
    end 
end) 
0
"player" wasn't defined in the second paragraph, so I moved the end for the playeradded event to the end of the second paragraph, and... IT STILL SAYS REFRESHED WHEN I DIE! This is infuriating! Zerio920 285 — 9y
0
No need to thumbs down. Relatch 550 — 9y
0
Sorry, it's just that it's clear this hasn't been tested and it's just a total waste of time. Zerio920 285 — 9y
Ad

Answer this question