[PATHFINDING] How to move a humanoid to the next checkpoint once it reaches a certain range of the current checkpoint?

All in the title. Once it reaches a certain range of a checkpoint, I want the humanoid to move to the next checkpoint.

local Waypoints = Path:GetWaypoints()
for i, v in pairs(Waypoints) do
	if not Cancel then
		NPC_Humanoid:MoveTo(v.Position)
		if v.Action == Enum.PathWaypointAction.Jump then
			NPC_Humanoid.Jump = true
		end
		NPC_Humanoid.MoveToFinished:Wait()
		if not game.Workspace:FindFirstChild("PickupGun") then
			Cancel = true
		end
	end
end

Hi Mate is there more to this script ?

Appear like path and npc_humanoid are not definded ( unknown global )

Hey. You can just define it with a different humanoid, it will work. Do you know how to do what I am asking?

There is plenty more, just figured if someone knew they would say what to add.

local Path = PS:CreatePath()
Path:ComputeAsync(NPC_HRP.Position, game.Workspace.PickupGun.Position)
if Path.Status == Enum.PathStatus.NoPath then
	ChaseRandomPlayer()
else

NPC_Humanoid.MoveToFinished:Wait()

After this fires get the distance from the character’s current position to the position of the current checkpoint, if the distance is less than some threshold then move the character towards the next checkpoint otherwise continue moving the character towards the current checkpoint until it reaches a distance from it that is less than the required threshold.