NPC not healing

Hello, I am trying to make a training dummy in my game for me and other players to test out attacks. The NPC only has 100 health so to make it heal, I made a script and put it into the NPC so it could heal back up to 100.

Script:

while true do
	Humanoid.HealthChanged:Wait()
	task.wait(10)
	Humanoid.Health = 100
end

This script works fine until the NPC’s health reaches 0. The heal script stops working and there is no output.

This is because the NPC’s humanoid gets put in the Dead state which causes it to remain dead. You can try keeping a version of the NPC in ServerStorage then cloning the NPC and inserting it into workspace after the current clone dies. You can additionally put your script inside the NPC being cloned so any clones created will heal unless they die in which you should destroy the clone and as previously mentioned, create a new clone.

I made this script and put it in ServerStorage, but the NPC is still not healing.

Script:

local char = game:GetService("ServerScriptService"):WaitForChild("Storage").Parts.PracticeTarget
local humanoid = char.Humanoid

humanoid.Died:Connect(function()
	print("Cloning...")
	char:Clone()
	print("Cloned!")
	char:Destroy()
end)

None of the print statements are working. Any idea what’s wrong?

Try this:

local char = game:GetService("ServerScriptService"):WaitForChild("Storage").Parts.PracticeTarget

while true do
	
	local newChar = char:Clone()
	local newCharHumanoid = newChar:WaitForChild("Humanoid")
	newChar.Parent = workspace
	
	newCharHumanoid.Died:Wait()
	
	task.wait(1) --respawn cooldown (not required)
	
	newChar:Destroy()
	
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.