So I have a npc that attacks anything humanoid this is the script.
function findNearestPlayer(Position)
wait(0.3)
local List = game.Workspace:children()
local Torso = nil
local Distance = 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("HumanoidRootPart")
Human = Temp2:findFirstChild("Humanoid")
if (Temp ~= nil) and (Human ~= nil) and (Human.Health > 0) then
if (Temp.Position - Position).magnitude < Distance then
Torso = Temp
if game.Players:GetPlayerFromCharacter(Temp) then
Distance = (Temp.Position - Position).magnitude
end
end
end
end
end
return Torso
end
while true do
local target = findNearestPlayer(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end
end
Why does he attack anything thats humanoid and not only players? I put line 17 in but it still doesn't work. I want him just to attack players. The duplicated npc has the exact same everything from the first one. I just clicked ctrl d and moved my npc2 next to my npc 1 to test. The script I pasted in my post is the follow script which is the movement. There is also a damage script and animation script for walking and stuff but that doesnt matter.

2 comments
That's not gonna fix it.
He tried to make it so it only attacks players though...