1
votes

basically I'm making a script that prints "played died" when the certain person dies though when the person dies, the script stops working. Here's the source:

local hum = game:GetService("Players").LocalPlayer.Character.Humanoid

hum.HealthChanged:connect(function(health)
if (health == 0) then
print("player died!")
end
end)

The script only works once, how do I make it work again when the character respawns?

1

1 Answers

0
votes

Roblox's Humanoid class has a "Died" event, can I ask why you aren't using that? It fires whenever the humanoid is decapitated or the health is directly set to 0.

In your usage, I would personally try:

hum.Died:connect(function()
    print("A player has died!");
end)

The example they provide on their site for a script that prints the player's name along with a death message is:

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            print(player.Name .. " has died!")
        end)
    end)
end)

Here are a few links that may be useful to you:

http://wiki.roblox.com/index.php?title=API:Class_reference

http://wiki.roblox.com/index.php?title=API:Class/Humanoid

http://wiki.roblox.com/index.php?title=API:Class/Humanoid/Died