How do i make an npc respawn after 5 seconds

hello everyone
i am trying to let my npc respawn after 5 seconds but if i add wait(5) in the script, it just does not respawn anymore. here is the code:

name=“Humanoid”

robo=script.Parent:Clone()

while true do
if script.Parent.Humanoid.Health<1 then
wait(5)
end
robo=robo:Clone()
robo.Parent=script.Parent.Parent
robo:makeJoints()
script.Parent:remove()
end
end

1.i want someone that explains to me why this does not work and how i can fix it
2.the isue is that it does not respawn and i want it to respawn after 5 seconds
3.i looked for a solution on the developer hub and i found one but it did not work for me

2 Likes

Do it like this:

Local humanoid= script.Parent.Humanoid 

humanoid.Died:connect(function()
Wait(5)
Local robo=robo:Clone()
robo.Parent=script.Parent.Parent
robo:makeJoints()
script.Parent:Destroy()
end)
1 Like

Use Destroy() instead of Remove(), for the rest you did it right.

1 Like

Haha yes remove is deprecated thanks for letting me know

1 Like

do i need to place it in the npc or in the humanoid

Put it In the NPC. Ignore this message because I need more word on this message because dev forum minimum character is bad

it does not respawn (text text text)

Firstly is it a script it shouldn’t be a local script secondly did you put it in the NPC model itself or you put it in the Npc part if you are confuse where you put pls show me the workspace where the npc is and every of his stuff

i am a little confused

Okay its good but show me the script you’ve written

Okay my bad I didn’t write it correctly here try this one:

local humanoid= script.Parent.Humanoid 
local robo = script.Parent
humanoid.Died:connect(function()
wait(5)
local robo1 =robo:Clone()
robo1.Parent=script.Parent.Parent
robo1:makeJoints()
script.Parent:Destroy()
end)

Now it should work i fixed the script again

hmm stil does not work (text text)

I just edit the script try it again


still doesnt

Did you wait 5 sec after it died?

yes (text text text text text)

Okay wait try this one :

local humanoid= script.Parent:WaitForChild("Humanoid")
local robo = script.Parent
humanoid.Died:connect(function()
wait(5)
local robo1 =robo:Clone()
robo1.Parent=script.Parent.Parent
robo1:makeJoints()
script.Parent:Destroy()
end)

Also try opening the output and see if there is any error if that script i am giving you isn’t working


there is no error but it seems like the script does not get activated

Bruh you removed the Humanoid line in the script re copy that again :

local humanoid= script.Parent:WaitForChild("Humanoid")
local robo = script.Parent
humanoid.Died:connect(function()
wait(5)
local robo1 =robo:Clone()
robo1.Parent=script.Parent.Parent
robo1:makeJoints()
script.Parent:Destroy()
end)