local function q(q)local n={q[1].Position}local g=(q[2].Position-q[1].Position).Unit if#q>2 then for M=2,#q-1,1 do local N=(q[M].Position-n[#n]).Unit if not N~=g then table.insert(n,q[M].Position)g=N end end end return n end return function(n,g,M)if M then path=PathfindingService:CreatePath()end path:ComputeAsync(n,g)if path.Status==Enum.PathStatus.Success then local n=q(path:GetWaypoints())return n else return false end end

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
