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