Laggy pathfinding?

Hi so im making a patrol system and for some reason its become really like stop and start. It moves to one waypoint and then stops and then goes to another. This only happens a few minutes after starting

while wait(math.random(20,110)) do
	if lastPoint ~= nil then
		lastPoint.Value.Value = false
	end
	repeat number = math.random(1, #waypoints) until waypoints[number].Value.Value ~= true
	waypoints[number].Value.Value = true
	lastPoint = waypoints[number]
	local success, errorMessage = pcall(function()
		path:ComputeAsync(npc.PrimaryPart.Position, waypoints[number].Position)
	end)

	if success then
		for _,waypoint in pairs(path:GetWaypoints()) do
			humanoid:MoveTo(waypoint.Position)
			humanoid.MoveToFinished:Wait()
		end
	else
		warn(errorMessage)
	end
end

3 Likes