It's been years since I've been last online, and after a while, I got into this.. problem. I was testing my NPC to see if it can chase me like an anti-human robot thingy, but this problem popped up out of nowhere and began killing my own NPC which spammed my Output because I placed a respawn function in the code (not included below).
For some reason, I have no idea how to fix the problem below so thats why i asked for help here.
function findplayer(pos) print(pos) local list = game.Workspace:GetChildren() local torso = nil local dist = script.Parent.Stats.Distance.Value local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) then temp = temp2:FindFirstChild("Torso") human = temp2:FindFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) and (script.Parent.Torso.Position - OrigPos).magnitude <= script.Parent.Stats.ChaseDistance.Value then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end while wait(.2) do local target = findplayer(script.Parent.Name) --Here's the area where the problem occurs SwiftRage if target ~= nil then script.Parent.Entity:MoveTo(target.Position, target) end end
Thanks in advance! -GD Endermanium ( ?° ?? ?°)
Its Looking For the Humanoid try changing the Name Of Humanoid for something like HumanoidNPC in your NPC models