--Func

local function condensePath(paths)
    local newWaypoints = {
        paths[1].Position
    }
    local lastUnit = (paths[2].Position - paths[1].Position).Unit

    if #paths > 2 then 
        for i = 2, #paths - 1 do 
            local thisUnit = (paths[i].Position - newWaypoints[#newWaypoints]).Unit

            if not thisUnit ~= lastUnit then
                table.insert(newWaypoints, paths[i].Position)
                lastUnit = thisUnit
            end 
        end 
    end

    return newWaypoints
end 

return function(pointA, pointB, refreshPath)
    if refreshPath then
        path = PathfindingService:CreatePath()
    end
    path:ComputeAsync(pointA, pointB)

    if path.Status == Enum.PathStatus.Success then
        local waypoints = condensePath(path:GetWaypoints())

        return waypoints
    else 
        return false
    end 
end
