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

Made a "died" script to detect a player's death, only works once?

Asked by 5 years ago

The following code should print "died!" when a player dies:

game.Players.PlayerAdded:Connect(function(client)
    repeat wait()

    until client.Character ~= nil and client.dead ~= nil

    client.Character.Humanoid.Died:Connect(function()
        client.dead.Value = true
        print("died!")
        print()
    end)
end)

The problem is that "died!" does print when the player dies, but won't print if they die again, meaning it didn't detect their deaths after the 1st one. Anyone know the problem? Also, is there a better way to detect when players die?

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

You have it only set to when the player joins, not when the character loads in to. This isn't tested, but it should work.

game.Players.PlayerAdded:Connect(function(client)
client.CharacterAdded:connect(function(Character)
    repeat wait()

    until client.Character ~= nil and client.dead ~= nil

    client.Character.Humanoid.Died:Connect(function()
        client.dead.Value = true
        print("died!")
        print()
    end)
end)
Ad

Answer this question