Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Some problem to my NPC that randomly happened.. Help?

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 ( ?° ?? ?°)

1 answer

✓ Accepted answer

Its Looking For the Humanoid try changing the Name Of Humanoid for something like HumanoidNPC in your NPC models

This discussion is preserved as it was. New answers, comments, and votes are closed.