Auto updating pathfinding stutters when updating

in the video, the pathfinding updates every time i move.


the issue is that it stutters in the beginning of the recreation of the path when updating

here’s the code

			while true do
				if Pathfinding.Paths[Selection] ~= Goal then
					coroutine.yield()
				else
					local Current = NewestCFrame
					local Path = PathfindingService:CreatePath()
					Path:ComputeAsync(Selection.HumanoidRootPart.Position, NewestCFrame.Position)
					for Iteration, Waypoint in pairs(Path:GetWaypoints()) do
						NewestCFrame = Goal.CFrame * Offset
						if Current ~= NewestCFrame then
							break
						end
						Selection.Humanoid:MoveTo(Waypoint.Position)
						if Waypoint.Action == Enum.PathWaypointAction.Jump then
							local Moving = true
							Selection.Humanoid.MoveToFinished:Connect(function()
								Moving = nil
							end)
							repeat Selection.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping) task.wait(0.1) until not Moving
						else
							Selection.Humanoid.MoveToFinished:Wait()
						end
					end
					if Current == NewestCFrame then
						Selection.Humanoid:MoveTo(NewestCFrame.Position)
					end
				end
			end

It’s probably stuttering because every time you move it has to recalculate the path

You’d probably solve by letting the npc continue to walk down the pathfind while the code is calculating the next pathfind, probably by using two coroutines instead of one.

wouldn’t it lag if i was doing this in studio instead of being slow? or does pathfinding service limit itself on how much path can be recalculated at a time