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?
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.