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

6 comments
When you use . Instead of : , the first parameter is always the table/object.
On what line your talking about @incapz
line 2, also i don't think so?
That isnt the issue re read the questioni asked.
why are you making it go to a random waypoint each time? (unrelated, but just curious)
i want the character to go to its work place sit then get up to get papers or to get some drinks. Make it look dynamic