Im making multiple npcs pathfind at once, ive been having problems trying to fix the npcs pathfind, it works when its only used on one but breaks when used with multiple.
it returns false.
PATHFINDING MODULE
function Pathfind.MoveToPos(character, Destination)
local Humanoid = character:FindFirstChildOfClass("Humanoid")
local HumanoidRootPart = character.HumanoidRootPart
local path = PathfindingService:CreatePath({
["AgentCanJump"] = true,
})
local success, errorMessage = pcall(function()
HumanoidRootPart:SetNetworkOwner(nil)
path:ComputeAsync(HumanoidRootPart.Position, Destination.Position)
end)
-- gets the basic stuff down.
if success and path.Status == Enum.PathStatus.Success then
local Waypoints = path:GetWaypoints()
if Waypoints and Waypoints[3] then
local Data = Waypoints[3]
if Data.Action == Enum.PathWaypointAction.Walk or Waypoints[3].Action == Enum.PathWaypointAction.Jump then
task.spawn(function()
Humanoid:MoveTo(Waypoints[3].Position)
Humanoid.Jump = true
end)
end
Humanoid:MoveTo(Data.Position)
-- Checks actions
end
else
return false
end
end
SERVERSIDEDSCRIPT
local CollectionService = game:GetService("CollectionService")
local PathfindHandler = require(game.ReplicatedStorage.Files.Modules.Pathfind)
while task.wait(0.1) do
task.spawn(function()
local Base = workspace.ChosenMap:FindFirstChildWhichIsA("Folder"):FindFirstChild("MainBase")
for i, v in pairs(CollectionService:GetTagged("Base")) do
PathfindHandler.MoveToPos(v, Base)
-- makes all of them move at once
end
end)
end