Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to get only the closest part in a pair instead of everything in it?

Asked by 2 years ago

so, im trying to make my npc find only the closest part in a pair, but instead it gets all of the parts and goes for the first one, is there a way around it?

function FindJob()
    local DistMin = 500

    for _,v in pairs(game.Workspace.Waypoints.Trabalho:GetChildren()) do
        local Pos2 = v.Position
        local dist = (Pos - Pos2).magnitude
        if dist <= DistMin then
            destination = Pos2
            followPath(destination)
            print(destination)
        end
    end
end

Answer this question