Server Script inside of both NPCs:
local pathfindingService = game:GetService("PathfindingService")
local humanoid = script.Parent.Humanoid
local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")
local destination1 = game.Workspace.dest1p2.Position
local destination2 = game.Workspace.destEND.Position
local path = pathfindingService:CreatePath()
path:ComputeAsync(body.Position, destination1)
local waypoints = path:GetWaypoints()
for k, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoint.Position)
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid.MoveToFinished:Wait()
end
wait(20)
path:ComputeAsync(body.Position, destination2)
local waypoints = path:GetWaypoints()
for k, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoint.Position)
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid.MoveToFinished:Wait()
end
I want it so when one NPC finished the path, the other NPC does a path and it just keeps switching back and forth. Ex: The 1st NPC starts its path and then after a little while it gets back to the start. I then want the 2nd NPC to start its path until it eventually gets back to the beginning and then the 1st NPC starts its path again and then eventually gets back to the start then the 2nd NPC starts its path again and so on.

1 comment
Is there a way I could use an If then statement to tell if the NPC was touching a part to then trigger the rest of the script on the other NPC to start its path.