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

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

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

✓ Accepted answer

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)

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