Hi, I am making a map voting system, and I want to find out what map the highest number is. However, I have no clue on how to do it. Can someone help? Here is my current script:
local cons = tonumber(workspace.Lobby.Construction.SurfaceGui.TextLabel.Text)
local city = tonumber(workspace.Lobby.Construction.SurfaceGui.TextLabel.Text)
local chosen = "nil"
local numberTable = {city,cons}
for i, v in pairs(numberTable) do
local number = v
if number > highestnumber then
highestnumber = number
end
end
local ChosenMap = highestnumber
task.wait(0.3)
Status.Value = ChosenMap.Name.. " has been chosen!"
task.wait(2)
Status.Value = "Game starting!"
hi there, you can do something like this, just a simple system.
local cons_text = tonumber(workspace.Lobby.Construction.SurfaceGui.TextLabel.Text)
local city_text = tonumber(workspace.Lobby.Construction.SurfaceGui.TextLabel.Text)
local cons = {}
local city = {}
setup a table for each map, in the future make a function that does this btw
next you compare the lengths of the 2 tables:
local function getMostVoted(mapA, mapB)
return #mapA > #mapB
end
then call the function
local ChosenMap
if #cons ~= #city then
local votes = getMostVoted(cons, city)
if votes == false then
ChosenMap = city
return ChosenMap
end
ChosenMap = cons
return ChosenMap
elseif #cons == #city then -- if both have the same votes
local c2 = {1,3,5,7)
local c3 = (2,4,6,8)
local num = math.random(1,8) -- pick a random number
if table.find(c3, num) then ChosenMap = city return end -- if the number is 2,4,6,8
if table.find(c2, num) then ChosenMap = cons return end -- if the number is 1,3,5,7
end
end
U can use
math.max(votedmap1,votedmap2,votedmap3) == votedmap1
if is true then this map was voted
U can change votedmap1 for other.
1 Like