Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I get the largest of the table?

Asked by 4 years ago

I've been confused while trying to make a script that picks the biggest number in a table

local table = {50,12,78}
for i,v in pairs(table) do
    --what do i do here?
end

1 answer

Log in to vote
0
Answered by
Robowon1 323 Moderation Voter
4 years ago

Try this:

local table = {50,12,78}
local highest = 0


for i,v in pairs(table) do
    if v > highest then
highest = v
end
end
0
Thanks User_3805 6 — 4y
0
table.sort is better SoftlockedUnderZero 668 — 4y
Ad

Answer this question