How to make pathfinding not target certain players

what is the issue? It works perfectly.i just tested it.

It never sets the bool based on team color, and it looks for a bool of a different name in the SetPlayerChase function

Same issue as before

why do i have to put this part here

Okay i fixed that part. It works now. I hadnt tested the SetPlayerChase lol. Please mark the code as the solution.

Can I see the updated code?

WHY

local playerService = game:GetService("Players")
--local players=playerService:GetPlayers()


playerService.PlayerAdded:Connect(function(player) --give chase bool to all new players
	local bool = Instance.new("BoolValue")
	bool.Parent = player
	bool.Name = "CanChasePlayer"
	bool.Value = true
end)

local function SetPlayerChase(player, boolValue)
	player:WaitForChild("CanChasePlayer").Value = boolValue
end



local npc = script.Parent
local human = npc.Humanoid

local PFS = game:GetService("PathfindingService")
local RUNSERVICE = game:GetService("RunService")

npc.PrimaryPart:SetNetworkOwner(nil)


local function findTarget()
	local players = game:GetService("Players"):GetPlayers()
	local nearesttarget
	local maxDistance = 75 -- distance

	for i,player in pairs(players) do
		if player:FindFirstChild("CanChasePlayer").Value == true then
			print("hi")
			if player.Character then
				local target = player.Character
				local distance = (npc.HumanoidRootPart.Position - target:WaitForChild("HumanoidRootPart").Position).Magnitude

				if distance < maxDistance then
					nearesttarget = target
					maxDistance = distance
				end

			end 
		end
	end
	return nearesttarget
end

local function getPath(destination)
	local path = PFS:CreatePath()

	path:ComputeAsync(npc.HumanoidRootPart.Position, destination)

	return path
end

local function pathFindTo(destination)
	local path = getPath(destination)
	local target = findTarget()

	if target and target.Humanoid.Health > 0 then
		for i,waypoint in pairs(path:GetWaypoints()) do

			if waypoint.Action == Enum.PathWaypointAction.Jump then
				human.Jump =true
			end

			human:MoveTo(waypoint.Position)
			human.MoveToFinished:Wait()

		end
	end
end

RUNSERVICE.Heartbeat:Connect(function()
	local target = findTarget()

	if target then
		pathFindTo(target:WaitForChild("HumanoidRootPart").Position + (target:WaitForChild("HumanoidRootPart").Velocity.Unit * 1))
	end
end)```

Still doesnt work

tgrerfedrewsde

what do you mean it doesn’t work? Nobody can help you if you aren’t specific. I tested it and it works fine so I’m not sure what you mean.

If the value was originally false, and you change it to true, the ai will still act like it was false

sounds to me like you’re changing it on the client. You have to change it on the server. Are you changing it scriptually or during testing in the workspace tab?

I feel like such an idiot, thanks