So I'm trying to make a piece of code, that basically says 3 numbers in a table, and I want the script to print the highest number. I am really confused so if someone could help me that'd be great!
local Table {1,2,3} for i,v in pairs(Table) do print(Table.MaxValue) end
local Table = {1,2,3} local HighestValue = 0 for i,v in pairs(Table) do -- iterate through table if v > HighestValue then -- check if value in table is greater than the highest value so far HighestValue = v -- sets highestvalue if it his greater than end end print(HighestValue) -- prints 3 (the highest number) to output
You could also make it into a function
function GetHighestNumber(Table) local HighestValue = 0 for i,v in pairs(Table) do if v > HighestValue then HighestValue = v end end return HighestValue end local Table1 = {1,2,3} local HighestNumber = GetHighestNumber(Table1) print(HighestNumber) -- Prints 3