The code is right here:
local Temp2 = nil
for x = 1, #List do
Temp2 = List[x]
if (Temp2.className == "Model") and (Temp2 ~= script.Parent) then
Temp = Temp2:findFirstChild("HumanoidRootPart")
Human = Temp2:findFirstChild("Humanoid")
local plr = Human.Name
if players:FindFirstChild(plr) then
if (Temp ~= nil) and (Human ~= nil) and (Human.Health > 0) then
if (Temp.Position - Position).magnitude < Distance then
Torso = Temp
Distance = (Temp.Position - Position).magnitude
end
end
end
end
return Torso
end
end
while true do
local target = findNearestPlayer(script.Parent.HumanoidRootPart.Position)
if not target.Name == ("Goblin") then --how i try to make them not attack eachother
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end
end
end
I do not get any errors.

2 comments
although it does work, now the npc seems to detect me from any range
Set closestDist to the maximum range you want (ex
local closestDist = 50on line 3) and then removenot closestDist oron line 11 so that it just saysif dist < closestDist then