✓ Accepted answer
##Problem
You're returning nil too early in your findNearestTorso function. When the first player joins the server, that will be the only player targeted. If that player is not within 25 studs of the AI, the function will return nil not checking the other players.
##Solution
Return nil after the for loop has finished. That way all players are processed, and the AI may confirm no one is within range.
##Final Script
function findNearestTorso()
for _, plr in pairs(game.Players:GetChildren()) do
while not plr.Character do wait() end
if plr.Character:findFirstChild("Humanoid") then
if (trooper.Torso.Position - plr.Character.Torso.Position).magnitude <= 25 then
return plr.Character.Torso
end
end
end
return nil
end
######Hopefully this answered your question. If it did, do not forget to hit the accept answer button. If you have any questions, feel free to ask them in the comments below.
1 comment
Why remove the script? It's good to keep it for reference.