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.
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
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 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
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)
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