I could easily find this on roblox forums, too bad those idiots removed them. Anywho, how would I print the highest value on a table of numbers?
COMMUNITY QUESTION
Find the highest value on a table?
2 answers
local highest = 0
local nums = {5,10,105,35,2,.1,401}
for i,v in pairs(nums)do
if v > highest then
highest = v
end
end
print(highest)
This makes a variable called "highest" which is set to 0 (could set it lower if you're getting the highest of negative numbers) then iterates through the table containing numbers and sets the value of highest to the variable if it is higher than the last.
The best way to do this would be Iteration with a For loop. Here's an example:
local min = 0 -- Use this to set your minimum number if you want, totally up to you.
local numbers = {1, 2, 3, 4, 5}
function findHighest(table)
local highest = 0
for i, n in pairs(table) do
if n > min then
min = n
highest = n
end
end
return highest
end
local highestInNumbers = findHighest(numbers)
You can then use highestInNumbers to reference later.
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
The ROBLOX Staff built the entire ROBLOX platform for you to make your games on, I'd advise you not to call them "idiots".
That was an essential part of ROBLOX that everyone enjoyed and has been there forever. It's worse than when they removed tix lmao
^
bro yall are actual cringe