Roblox pathfinding pacing back and fourth

Recently I’ve been trying to develop a script for moving multiple units from point A to point B, but, instead of doing what I ordered them to, they pace back and fourth for no good reason. Not sure if its something wrong with my script or roblox, at this point I might just do whatever A* is, but I don’t know how or why.

Here’s my code:

function RunCollectionMove(finalPosition,unit,FaceDirection)
	spawn(function()
		
		unit.HumanoidRootPart:SetNetworkOwner(nil)
		
		local unitPath = PathfindingService:CreatePath()
		unitPath:ComputeAsync(unit.HumanoidRootPart.Position, finalPosition)
		
		wait(math.random(100,200)/100)
		
		if unitPath.Status == Enum.PathStatus.Success then
			local waypoints = unitPath:GetWaypoints()

			for i, v in pairs (waypoints) do

				unit.Humanoid:MoveTo(v.Position)
				unit.Humanoid.MoveToFinished:Wait()

				if v.Action == Enum.PathWaypointAction.Jump then
					unit.Humanoid.Jump = true
				end
				
				if (waypoints[#waypoints].Position - finalPosition).magnitude > 15 then
					break
				end
			end
		end
		
		wait(math.random(100,500)/100)
		
		local info = TweenInfo.new(2,Enum.EasingStyle.Sine)
		
		local CFrameValue = Instance.new("CFrameValue")
		CFrameValue.Value = unit:GetPrimaryPartCFrame()

		CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
			unit:SetPrimaryPartCFrame(CFrameValue.Value)
		end)

		local Angle = FaceDirection

		local Spin = TweenService:Create(CFrameValue, info, {Value = (Angle - Angle.Position) + unit.HumanoidRootPart.Position})

		Spin:Play()
		
		Spin.Completed:Connect(function()
			Tighten(unit)
		end)
	end)
end

Does anyone know how to fix this?

1 Like

Have you tried messing around with the agent parameters? Is it also possible that they are blocking eachother? Perhaps disable their collisions or give the unit its own collision group so they can’t collide with themselves.

1 Like

They might be pathfinding around the old positions, thus leading to a weird path.
If you make them ignore the current positions of all the other soldiers, they could stop doing that.

Other soldiers collisions are set to off for them

try to set down a bunch of parts on their path and see where they’ll go. That might help debug them.

1 Like