I have two NPC's down on the level and they attack eachother as soon as I run it.
local larm = script.Parent:FindFirstChild("Left Arm")
local rarm = script.Parent:FindFirstChild("Right Arm")
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 20
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) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
while true do
wait(0.1)
local target = findNearestTorso(script.Parent.Torso.Position)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end
end
I have found the problem, in the scripting I said "findnearesttorso" but I don't know any other way of doing this.
Is there any way I can keep NPC's from attacking eachother but attack players?

2 comments
It worked. Appreciated! But they don't attack the player anymore.
Perhaps I should put it into more detail; When the player comes in range, it will sit there and attack with its sword. It will not move from its position at all though