Find most voted map in Lua for Roblox
Posted by alex 1 year, 7 months ago
On May 16, 2023
My son was trying to solve the issue of find the most voted on map in his Roblox game. We came with the solution below.
local listOfMaps = {
{"sandLands", game.Workspace.SandLands.Value};
{"grassLands", game.Workspace.GrassLands.Value};
}
table.sort(listOfMaps,function(a,b)
return a[2] > b[2]
end
)
local mapFound
for i,v in pairs(listOfMaps) do
mapFound = v[1]
break
end
-- sandland wins --
if mapFound == "sandLands" then
script.Parent.Text = 'Sand Lands won the map vote!'
if mapFound == "grassLands" then
script.Parent.Text = 'Grass Lands won the map vote!'