How to check what value is the greatest

Is it possible to get all the values in a table? What do I mean by this? Basically, You would have a table. Like this:

local votes = {
	Map1 = 6;
	Map2 = 2;
	Map3 = 7;
}

And what I want to know is how can we check which one has the highest value
(in this case its map3)?

local mostVotesName
local mostVotesValue
for i, v in votes do
if not mostVotesName or (mostVotesName and v > mostVotesValue) then
mostVotesName = i
mostVotesValue = v
end
end

print(`Map {mostVotesName} had the most votes ({mostVotesValue})`)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.