I am trying to make this death detection script and it is not working. This is a LocalScript in StarterCharacterScripts. The problem is that “you died” is not printing when I reset my character during playtesting.
local player = script.Parent.Humanoid
if player.Health == 0 then
print("you died")
end
I have a better way if you want it to make it local like a GUI saying you died:
First, place it in PlayerGui or StarterCharacterScripts as a localgui
local Player = game.Players.LocalPlayer
local PlayerCharacter = Player.Character
PlayerCharacter.Humanoid.Died:Connect(function())
print("Player died")
end)
If you have to make it a localscript, you can do it like this:
local player = game.Players.LocalPlayer
local character = player.Character
character:WaitForChild("Humanoid").Died:Connect(function()
print(player.Name .. " has died!")
end)