How do you make simple AI follow specific players only, I have 2 types of players:
Infected
None Infected
The AI should only follow the None Infected group of players, I can use booleans to define that instead of Playerteams. I only need a way to make the AI to not follow specific players and follow the rest.
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 1000
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.5)
local target = findNearestTorso(script.Parent.Torso.Position)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end
end
here’s a suggestion u can use Bool values named “Infected”, attributes or tables, but let’s say you use bool values then we’ll put them inside the player’s characters we can just(but it seems like you already know about this assuming from what you said?)
if temp2.Infected.Value == false then
--- Follow this guy
end
Alternatively, if your game has no NPCs that it’ll be following around, you can use Players:GetPlayers() to retrieve their Characters and Team. Downside being if they die, the character object tends to mess up a bit. (though this is mainly apparent on LocalScripts)
no I meant that temp2 is the workspace Character of the player, and since that the boolean is not inside the Character, if theres a way to call from game.Players