i.e if Player health == 0 then print('ded') end
✓ ANSWER ACCEPTED
how do i make a script that detects when the player dies and prints out value?
2 answers
✓ Accepted answer
You can do this with the Humanoid.Died event.
i.e
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)
Hey RealRexTeam,
The humanoid has a .Died event that you can use to detect when the player dies. I recommend just attaching it to the .CharacterAdded() function so that it runs at all times while the player is alive and it is well formatted that way. Here, I'll show you an example of it below.
####Script
local plrs = game:GetService("Players"); -- The players service
plrs.PlayerAdded:Connect(function(plr) -- PlayerAdded anonymous function with parameter of the player.
plr.CharacterAdded:Connect(function(char) -- CharacterAdded anonymous function with parameter of the player.
local hum = char:WaitForChild("Humanoid"); -- The humanoid in the Character.
hum.Died:Connect(function() -- .Died anonymous function
print("Humanoid has died.") -- Prints "Humanoid has died."
end) -- end for .Died function.
end) -- end for .CharacterAdded function.
end) -- end for .PlayerAdded function
###Well, I hope I helped and have a nice day.
~~ KingLoneCat
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
ty