Does not classify "enemy" as dead

I am currently trying to program a ragdoll on death system, but when the “Health” number value is below 1, nothing happens.
This is my code:

local Humanoid = script.Parent:WaitForChild("Humanoid")
local health = script.Parent.Health.Value

while true do
if health < 1 then
	print("enemyDead")
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Flying, false)
	Humanoid.PlatformStand = true
	end
end

I can decrease the health just fine, but it doesn’t even print the “enemyDead” message in the output.

I believe it is because health is always a static value: 100

you should do:

local health = script.Parent.Health

--then in while loop replace with:

if health.Value < 1 then

as @Velliaan says, you should rely on a .changed or equivalent event to negate unnecessary while loops

This is because you’ve gotten health.Value meaning it’ll never change since it’s just a number and not a instance, you want to do script.Parent.Health, i also recommend doing health.Changed:Connect(function() over looping

I still do not think it worked.
My new code:

local Humanoid = script.Parent:WaitForChild("Humanoid")
local health = script.Parent.Health

health.Changed:Connect(function()
	if health.Value < 1 then
		print("enemyDead")
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Flying, false)
		Humanoid.PlatformStand = true
	end
end)


instead of calling health before call it inside the connect function so that it updates the health instead of being the first time

instead of doing if health.Value < 1 then replace it to if script.Parent.Health.Value < 1 that way it updates and isnt referencing a health from before it was changed

My bad for not reading your code properly i was assuming it was a number value, what you want to do is the following:
Humanoid. GetPropertyChangedSignal(“Health”):Connect(function()
if Humanoid.Health < 1 then

Yes this would be correct bbbbb

I am using a number value, sorry for making it unclear.

Are you sure your health value is changing at all? Check whilst playing in studio to see if it’s changing

Yes, i checked and the health value is changing.

local Humanoid = script.Parent:WaitForChild("Humanoid")

script.Parent.Health.Changed:Connect(function()
	if script.Parent.Health.Value < 1 then
		print("enemyDead")
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Flying, false)
		Humanoid.PlatformStand = true
	end
end)

I probably messed something up in the code.

And the health value is going below 1? if it stops at 1 then <= , if not make sure you have the correct instance, the script isn’t disabled, and the effects are server sided (damage) if it’s still not working you’ll probably need to provide the code that applies damage and a explorer layout of your model

I think I see my issue, I made the damage script a LocalScript. I will see if it works if I change it to a normal script.

Yep, that worked. Thanks for the help!

Humanoid instances have a “Died” RBXScriptSignal object which is fired whenever that humanoid dies. I recommend you use that instead.

local npc = script.Parent
local npcHumanoid = npc.Humanoid

npcHumanoid.Died:Connect(function()
	npcHumanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
	npcHumanoid:SetStateEnabled(Enum.HumanoidStateType.Flying, false)
	npcHumanoid.PlatformStand = true
end)
1 Like