Checking for Humanoid death doesn't work

  1. What do you want to achieve? When a player dies, run code

  2. What is the issue? Code doesn’t run

  3. What solutions have you tried so far? I tried using Humanoid.Changed and Humanoid:GetPropertyChangedSignal(“Health”), and checking if the humanoid’s health is 0 or under, and I tried using Humanoid.Died.

Code:

game:GetService("Players").PlayerAdded:Connect(function(p)
       
   p.CharacterAdded:Connect(function(c)
   
      c:WaitForChild("Humanoid").Died:Connect(function()

         print("Player died")

      end)
   end)
end)

Try:

game:GetService("Players").PlayerAdded:Connect(function(p)
   p.CharacterAdded:Connect(function(c)
      local humanoid = c:WaitForChild("Humanoid")
      humanoid.Died:Connect(function()
         print("Player died")
      end)
   end)
end)

or:

game:GetService("Players").PlayerAdded:Connect(function(p)
   local character = p.Character or p.CharacterAdded:Wait()
   local Humanoid = character:FindFirstChild("Humanoid")
   Humanoid.Died:Connect(function()
       print(plr.Name.." has died")
   end)
end)

Sometimes it messes up and seems to not work properly.
Alternatively, I think you could check

A third option I could suggest is checking this post -

1 Like

The player or character may get added before the script loads, therefore not being detected by it. Since the script is related to the player character, you can parent it to StarterPlayer.StarterCharacterScripts to ensure it runs every time the character loads, then your script can be simplified to:

local Character = script.Parent --the script will be copied inside the character 
local Humanoid = Character:WaitForChild("Humanoid") 

Humanoid.Died:Connect(function()
	print("Player died") 
end)
1 Like