Sorry if it's a dumb question, but i'm still pretty new to the whole coding thing, and I thought I would get some more experienced opinions. I'm looking to have this script regenerate an npc if a certain amount of time passes, and the npc has full health.

The NPC is respawning, regardless of how much health he has, including full health.

I might just be a bingus, but thank you for taking the time to help me out!


object = script.Parent
if (object ~= nil) and (object ~= game.Workspace)and script.Parent.Humanoid.Health >= script.Parent.Humanoid.MaxHealth then 
model = object 
else
	end

backup = model:clone()  
waitTime = math.random(3,15)
wait(math.random(0, waitTime)) 
while true do 
wait(waitTime) 

model:remove() 


model = backup:clone() 
model.Parent = game.Workspace 
model:makeJoints() 

end 

7 comments

0

Any errors?

0

No, there's no errors in the log at all.

0

what is line 2 all about?

0

Lines 7 and 8 are supposed to be inside the if statement.

0

And there's nothing in else block either.

0

I think Humanoid.Health cannot be grater than Humanoid.MaxHealth.

0

And if Humanoid.Health is smaller than Humanoid.MaxHealth model:clone() will error because model is nil.