Confused on map voting system?

Hi forum! I’ve been working on a racing game where I want maps selected every round. I have created maps in the replicated storage with configuration values that contain the difficulty of the map and the title (which i want to display on a gui.) While I was working through this system I got a bit confused on how to make the map selection work (where 3 different maps get selected to have people vote on, I got the selection working its just the maps can be the same sometimes and I’m unsure how to work around this. I’m aware of tables but I got a bit confused)

local rs = game:GetService("ReplicatedStorage")
local remoteEventsFolder = rs.RemoteEvents
local votingEvent = remoteEventsFolder.Voting

local randomMap1 = rs.Maps:GetChildren()[math.random(1, #rs.Maps:GetChildren())]

local randomMap2 = rs.Maps:GetChildren()[math.random(1, #rs.Maps:GetChildren())]
if randomMap2 == randomMap1 then
	randomMap2 = rs.Maps:GetChildren()[math.random(1, #rs.Maps:GetChildren())]
	return
end
local randomMap3 = rs.Maps:GetChildren()[math.random(1, #rs.Maps:GetChildren())]
if randomMap3 == randomMap1 or randomMap3 == randomMap2 then
	randomMap3 = rs.Maps:GetChildren()[math.random(1, #rs.Maps:GetChildren())]
	return
end

print(randomMap1,randomMap2,randomMap3)

votingEvent:FireAllClients(randomMap1, randomMap2, randomMap3)

A way would be storing current available maps to choose from.

local Options = Maps:GetChildren()

then, you’d have a function ChooseRandomMaps that would pick a random map from options, remove it and insert it in a new array.

local function ChooseRandomMaps(amount: number): { string }
   local Options = Maps:GetChildren()
   local List: { string } = {}

   for index = 1, amount do
       local ChosenMap: Model = table.remove(Options, math.random(1, #Options)) --// table.remove returns the value it removed
       table.insert(List, ChosenMap.Name)
   end
   
   return List --// array of map names chosen
end

local function BeginVote()
    local VoteableMaps = ChooseRandomMaps(3)
    Vote:FireAllClients(VoteableMaps)
end

--// Then of course client sends the name of the map to server they voted of
--// Then server validates if player already voted, or if the map even exists
--// Then after voting, you determine by votes, if theres maps with same amount of votes
--// you simply choose between those
1 Like