Humanoid.Health Not working

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
2 Likes

Well first of all, you need to check if there is a humanoid on the brick

You should use Humanoid.Died instead of checking for the Health.

taken directly from the wiki: Humanoid | Documentation - Roblox Creator Hub

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)
2 Likes

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)

Adding to this @astra_wr Version is Serverside

Mine is ClientSide

Is this code still in a localscript within startercharacterscripts?

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)

@astra_wr Version is serverside, meaning its not a localscript and not in startercharacterscripts

I mostly think its log in serverside, to mostly you put it in ScriptService