Need Help With AI Problem!

Hello!

Recently, I ran into a problem with the AI, where the bot would shoot me even when I was on the same team as it. There is a dedicated allies variable but doesn’t seem to work anymore. If anyone has a fix for this, please help!

local allies = {game.Teams.British}

local potentialTargets = {game.Teams.Natives}
function findTarget()
	local dist = 200
	local target = nil
	potentialTargets = {}
	local seeTargets = {}
	for _,v in ipairs(workspace:GetChildren()) do
		local human = v:FindFirstChild("Humanoid")
		local torso = v:FindFirstChild("Torso") or v:FindFirstChild("HumanoidRootPart")
		if human and torso and v.Name ~= script.Parent.Name then
			if (myTorso.Position - torso.Position).magnitude < dist and human.Health > 0 then
				for i,x in ipairs(allies) do
					if x == v.Name then
						break
					elseif i == #allies then
						table.insert(potentialTargets,torso)
					end
				end
			end
		end
	end

If you need anymore of the script, please let me know, and ill send screenshots!

It doesn’t seem like your script is checking the team of a target at all.

The line

if x == v.Name then

does not check for a team.

Every player has a Team property. Perhaps you should check if the human in question is a player, and then check if their team is in the allies array

1 Like

Hi!

I’ve been working on this for about an hour now, it seems I can’t get it to work, here’s the original variable if it helps at all.

local allies = {script.Parent.Name,"Dev_BB1"}

local potentialTargets = {}