Having an error

Sup guys im having a problem with a script it is an respawning npc script it works but in the output it says an error.

.

my code is this

npc=script.Parent:clone()
local model = script.Parent
local humanoid = model.Humanoid

while true do
	wait(1)
	if humanoid.Health<1 then
		Npc=npc:clone()
		Npc.Parent=script.Parent.Parent
		Npc:makeJoints()
		script.Parent:remove()
	end
end
		



RobloxStudioBeta_118KqFGJX3

and this is my error
thanks

1 Like

You’re trying to :clone() a reference that is itself a :clone() and never has its parent set, so you’re potentially attempting to reference something the engines’ garbage collector has already cleaned up.
Try changing the reference npc=script.Parent:clone() to just npc = script.Parent and you’ll be able to properly clone it.

2 Likes

But it still appears me the same error.

Is variable Npc declared somewhere? Try changing the clone line to:
local Npc = npc:clone() so that the following lines have a proper variable to reference.

1 Like

Like @MP3Face stated, you are cloning the model twice for no reason.

I would suggest getting rid of the first line, and changing

to

Npc=model:Clone()

then continuing.

1 Like

Dang, this is a really old script.

1 Like