How to find the largest number in an array of numbers?

I’m trying to make a minigame voting screen, and I need to find the minigame with the most votes to select it to be played. How would I go around doing that?

local votes = {}
local minigames = {
"game1","game2"
}

local buff = 0
local minigame
-- you can save minigame's name in dictionary and then make a pairs with vote value
votes["game1"] = votenumber -- like this

for i,v in ipairs(minigames) do
    if votes[v] > buff then
        buff = votes[v]
        minigame = v
    end
end
print(minigame) -- it will print the minigame with the biggest vote value

table.sort is your friend.

https://developer.roblox.com/en-us/api-reference/lua-docs/table

local array = {
   {minigame = 'Example 1', votes = 1},
   {minigame = 'Example 2', votes = 5}
}

table.sort(array, function(a, b)
   return a.votes > b.votes
end)

Haven’t tested this code but the end result could be something resembling this.

1 Like

make an intvalue in the workspace of each minigame and if players wanna vote make a buttons and script to make if the player clicked on the button of the minigame the value +1 and see what minigame got the most votes