I'm trying to get the highest value of the table and I want to make sure its the final value before doing anything with it.
local table = {50,12,78} local highest = 0 for i,v in pairs(table) do if v > highest then highest = v end end
You can use table.sort
without the second argument (the second argument is a function of what is sorted (https://developer.roblox.com/en-us/api-reference/lua-docs/table) but the default uses lua operator <
.) to rearrange the table and their indexes.
Heres my example:
local a = {4,2,1,3}; table.sort(a) table.foreach(a,print) --[[ This prints: 1 1 2 2 3 3 4 4 if 4 is the highest value, therefore a[#a] is the highest value since 4 is at the last key. --]] print(a[#a])--> 4