Basically. What i want to do is when an enemy npc - we'll call attacker is going for a player. I want it to check if there is other attackers already attacking the player, and if there is 4 already there i want it to go for another player instead.
while sp.Parent~=nil and Humanoid and Humanoid.Parent~=nil and Humanoid.Health>0 and Torso and Head and Torso~=nil and Torso.Parent~=nil do
local _,time=wait(1/3)
humanoids={}
populatehumanoids(game.Workspace.Zulus)
closesttarget=nil
closestdist=sightrange
local creator=sp:FindFirstChild("creator")
for i,h in ipairs(humanoids) do
if h and h.Parent~=nil then
if h.Health>0 and h.Parent.Name~=sp.Name and h.Parent~=sp then
local plr=game.Players:GetPlayerFromCharacter(h.Parent)
if creator==nil or plr==nil or creator.Value~=plr then
local t=h.Parent:FindFirstChild("Torso")
if t~=nil then
local dist=(t.Position-Torso.Position).magnitude
for i,v in pairs (game.Workspace.NPCs:GetChildren()) do
local other = v.Torso
local mag=(other.Position-t.Position).magnitude
if mag<dist then
if i >=4 then
-- dont know what to put here
end
end
end
if dist<closestdist then
closestdist=dist
closesttarget=t
end
end
end
end
end
end
this is what i have so far
