NpcHealing not working properly

I have been here for 10 mins wondering why this is happening but im done, im finally asking

This code is supposed to heal the npc when it dies:

local humanoid = game.Workspace.Dummy.Humanoid

humanoid.Died:Connect(function()
	local humanoid = game.Workspace.Dummy.Humanoid
	humanoid.Health = 100
	print(humanoid.Health)
end)

After i kill the npc, what a surprise, it does not work! It prints 100 but its not healed… why?

why don’t you try better that when you kill the npc it is destroyed and another one is cloned in the same place?

1 Like

Yes, i could try that, but im still curious on why this is happening.

it could be a bug, to heal the npc idk why it happen

1 Like

https://developer.roblox.com/en-us/api-reference/property/Humanoid/Health

Health is a property that represents the current health of the Humanoid . The value is restricted to the range [0, Humanoid.MaxHealth ]. If the Humanoid is dead, Health is continually set to 0.

Herein lies your issue, the humanoid is dead so the health property is constantly set to 0.

1 Like

Once the dummy dies are you trying to define the location of a new dummy or the dummy that died? You’re trying to define it with the same parent and name, it’s humanoid may have health back to 100 but it’s already died, pretty sure it can’t be revived once its joints are broken,

1 Like
local humanoid = script.Parent.Humanoid
humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)

humanoid.HealthChanged:Connect(function(newHealth)
	if newHealth <= 0 then
		humanoid.Health = humanoid.MaxHealth
	end
end)

and here’s an example script which will fix your issue.

1 Like

Im trying to define it to the dummy that died, since i think i remember having a problem like this back then and that solved it, might aswell try it.