PathfindingService script is not working

So I was trying to visualize the shortest distance between 2 parts and this code just not work as I want to.

local PathService = game:GetService("PathfindingService")
local RunService = game:GetService("RunService")
local Blue, Red = workspace.Blue, workspace.Red
local folder = workspace.points
local bpos, rpos = Blue.Position, Red.Position
local Success = Enum.PathStatus.Success
local path = PathService:CreatePath(); 
local debounce = true

local function compute()
	print("Called")
	if debounce then
		debounce = false; path:ComputeAsync(bpos, rpos)
		print("Done")
		local waypoints = path:GetWaypoints();
		for i, waypoint in ipairs(waypoints) do
			local part = Instance.new("Part")
			part.Name = "waypoint"
			part.Anchored = true
			part.CastShadow = false
			part.CanCollide = false
			part.Size = Vector3.new(1,1,1) 
			part.Position = waypoint.Position + Vector3.new(0, bpos.Y, 0)
			part.Color = Blue.Color:Lerp(Red.Color, .5)
			part.Parent = folder
		end
		debounce = true
	end
end

RunService.Heartbeat:Connect(function()
	if Blue.Position ~= bpos or Red.Position ~= rpos then
		bpos, rpos = Blue.Position, Red.Position; compute()
	end
end)

compute()

It’s generating parts from random positions. I don’t know if the async thing is the problem.

What I’m actually trying to do is:

local RunService = game:GetService("RunService")
local folder = workspace.points
local Blue, Red = workspace.Blue, workspace.Red
local bpos, rpos = Blue.Position, Red.Position

RunService.Heartbeat:Connect(function()
	if Blue.Position ~= bpos or Red.Position ~= rpos then
		bpos, rpos = Blue.Position, Red.Position
		folder:ClearAllChildren()
		
		local dist = (bpos-rpos).Magnitude
		for i = .1, 1, .05 do
			local part = Instance.new("Part")
			part.Anchored = true
			part.CanCollide = false
			part.BrickColor = BrickColor.Random()
			part.BottomSurface = "Smooth"
			part.TopSurface = "Smooth"
			part.Size = Vector3.new(1,1,1)
			part.Position = bpos:Lerp(rpos, i)
			part.Parent = folder
		end
	end
end)