Help with npc respawn script

For some reason, it doesn’t detect the Humanoid Dying.
Prints “1”, “2” and that’s it, its a server script inside the npc, no output.

local RespawnTime = 5

while true do
	wait(.1)
	local char = script.Parent
	local Humanoid = char:WaitForChild("Humanoid")
	print("1")
	local clone = char:Clone()
	print("2")
	char.Humanoid.Died:wait()
	print("3")
	wait(RespawnTime)
	print("4")
	clone.Parent = game.Workspace
	print("5")
	script.Parent = clone
	print("6")
	char:Destroy()
	print("7")
end
3 Likes

I personally do something like this:

local clone = npc:Clone()
local respawnTime = 10

humanoid.Died:Connect(function() -- Humanoid died

wait(respawnTime) -- Wait until it's time to respawn
clone = clone:Clone()
clone.Parent = workspace
clone:MakeJoints()
local newHum = clone:WaitForChild("Humanoid") do -- Make it so it's actually alive
	newHum.Health = newHum.MaxHealth
end
npc:Destroy()

end)
5 Likes

The problem that I have is that the Humanoid.Died doesnt work.

Are you getting any errors, stuff like “tried to index nil with Died” or “Infinite yield possible on char:WaitForChild(“Humanoid”)”?

I have gotten no output errors. Also the npc is a tree, not a dummy. Is that a problem?

I think it might have to do with the while loop, perhaps try doing humanoid.Died:Connect() instead of humanoid.Died:Wait().

No, its dying, i have it set where my tool does over 1k and the hp bar drops

Actually the script only worked when i put it in a dummy, however I want to put this script in a tree model. however i got another free model dummy and tested the script there and it didnt work.