Find the lowest number in a table

I have a table

local MyTable = {2,6,8,12,9,3,8}

I need to find the lowest number (2) using a script.

How would I do this?
There is probably a really simple answer I just can’t think of it.

5 Likes
local min = math.min(table.unpack(MyTable))

math.min returns the smallest number out of its arguments.

You can also use table.sort:

table.sort(MyTable, function(a, b)
    return a < b
end)

Then the smallest number will be at index 1:

local min = MyTable[1]
27 Likes