So in my game, I have AI workers similar to Retail Tycoon. So I have this AI module that uses pathfinding service to go to the waypoints it sets. So i found out that the character tries to go to other waypoints they didn't even reach yet which makes them go into walls. So i made a Magnitude check to make sure if the ai is close the waypoint then go to the next, but if another AI moves the original AI in any other way it just stand still. How would i tackle this issue?
local module = {} function module.RunAI(Goal,Character) math.randomseed(tick()) math.random() local pfs = game:GetService("PathfindingService") local Waypoints = Goal:GetChildren() while true do local Waypoint = Waypoints[math.random(1,#Waypoints)] local FoundPath = pfs:FindPathAsync(Character.HumanoidRootPart.CFrame.p,Waypoint.CFrame.p) local Path = FoundPath:GetWaypoints() for i = 1,#Path do if Path[i].Action == Enum.PathWaypointAction.Jump then Character.Humanoid.Jump = true else repeat wait() until Path[i].Position.Magnitude - Character.HumanoidRootPart.CFrame.p.Magnitude < 4 Character.Humanoid:MoveTo(Path[i].Position) end end wait(math.random(2,8)) end end return module
I believe the culprit is line 15
repeat wait() until Path[i].Position.Magnitude - Character.HumanoidRootPart.CFrame.p.Magnitude < 4
This causes the AI to keep on waiting, and waiting. I think you meant to put the line under it in front of it?