''while wait(0.001) do'' script ignores the ''if mag < 0.5 then wait()'' when during a ''for waypoints'' pathfinding script

So uh… my script is this, what im tryna achieve is so the car npc can just wait for it and make a new pathfinding point when the wait is done, is somethings missing? the ‘‘if mag < 0.5’’ suppose to make a wait() that stops it for a while until its there, but however its not working. it just ignores it, any help?



while wait(0.001) do
	local PathfindingService = game:GetService("PathfindingService")
	-- Variables for the car and destination, etc.
	local Debris = game:GetService("Debris")
	primarypart = script.Parent
	local carprimary = script.Parent.FrontBumper
	local destination = script.Parent.MainTarget.Value
	local TweenService = game:GetService("TweenService")
    local modifier = script.Parent.Configuration.SpdModifier
	local path = PathfindingService:CreatePath{
		AgentRadius = 27
		
	}

	path:ComputeAsync(carprimary.Position, destination.Position)


	local waypoints = path:GetWaypoints()
	local part = Instance.new('Part')
	for  _, waypoint in pairs(waypoints) do
		Debris:AddItem(part, 8.5)
		part.Shape = "Ball"
		part.Material = "Neon"
		part.Name = "Pathfind_Point"	
		part.Size = Vector3.new(5.6, 0.6, 5.6)
		part.Transparency = 0
		part.Anchored = true
		script.Parent.Target.Value = part
		part.Parent = workspace
		part.CanCollide = false
		part.Position = waypoint.Position
		
		local mag = (primarypart.PrimaryPart.Position - script.Parent.Target.Value.Position).Magnitude / 3.25
		if mag < 0.5 then
			print(mag, 'mag to path')
			wait()	
		end			
	
	end
end

while wait(0.001) do

wait() can only fire delay at intervals of 1/30 seconds (0.033). Anything below that will go to that rate

print(mag, 'mag to path')
wait()	

As mentioned above, anything below 0.033 (including nil, as is the case with the wait() above) will revert to the 0.033.

The reason it seems as if nothing is happening is because the delay is so short.
If you want to connect the wait thing to an event you would do something like this:

EVENT:Wait()

or, (poor-ish practice but still a thing you can do)

repeat wait() until EVENT

You can only use task.wait() instead, as this reverts to 0.006, if not lower.

Yeah, task.wait() can give a shorter time at 60 ‘cycles’ per second. (or 0.0166666667 seconds minimum [like 3 times higher than the amount you suggested])

Is the print time not accurate?

  01:13:09.632  > print(task.wait())  -  Studio
  01:13:09.639  0.006548199999087956  -  Edit

Running it once will almost instantly wait, while running it multiple times will wait for ~1/60th of a second

  > print(task.wait())
  0.0010255999999344567
  > for i = 1, 10 do print(task.wait()) end
  0.0019191000000091663
  0.017823899999939385
  0.014895099999989725
  0.01690659999997024
  0.018807200000082958
  0.017832800000064708
  0.015919199999984812
  0.01787369999999555
  0.01581640000006246
  0.017849599999976817