I have a tower defense game, and I cant figure out how to find the lowest value from a table that contains instances and how far along they are along the path:
{
[Instance(ID)] = distance to treasure
}
Ive tried multiple methods to find the lowest value and get the instance from it, but i couldnt get it working. Heres the script:
function PlayLandUnit(tower, map)
local rangePart = tower.Range
local foundMobs = {}
local target
while task.wait() do
task.spawn(function()
local foundTouching = workspace:GetPartsInPart(rangePart, OverlapParams.new())
for i, v in pairs(foundTouching) do
if v:IsDescendantOf(map.mobs) then
foundMobs[v.Parent] = v.Parent.Distance.Value
end
end
target = -- get the index with the lowest value from foundMobs somehow here
if target then
print(target)
end
end)
end
end