Linking gamemodes to maps

I have 2 modules, 1 for getting maps, 1 for getting gamemodes. What I am trying to do is pick 3 random maps. Then pick 3 random gamemodes to assign to each map.

function MapManager:ChooseMap()
	local ChosenData = {}
	local ChosenMaps = {}
	local AllMaps = {}
	
	for _, v in pairs(Maps.Teams:GetChildren()) do
		table.insert(AllMaps, v)
	end
	
	for _, v in pairs(Maps.FFA:GetChildren()) do
		table.insert(AllMaps, v)
	end

	for i = 1, 3 do
		local RandomMap = math.random(1, #AllMaps)
		ChosenMaps[i] = AllMaps[RandomMap]
		table.remove(AllMaps, RandomMap)
	end
	
	local Gamemodes = GamemodeManager:GetRandomGamemodes(ChosenMaps)
		
	ChooseMap:FireAllClients(ChosenData)
end

-- GamemodeManager
local Gamemodes = {
	FFA = 'FFA',
	Teams = {'TDM', 'CTF', 'KOTH'},
}

function GamemodeManager:GetRandomGamemodes(chosenMaps)
	local ChosenGamemodes = {}
	
	for _, v in pairs(chosenMaps) do
		if v.Parent.Name == 'Teams' then
			local RandomGamemode = Gamemodes[math.random(1, #Gamemodes)]
			table.insert(ChosenGamemodes, RandomGamemode)
		else
			table.insert(ChosenGamemodes, Gamemodes.FFA)
		end
	end
	
	return ChosenGamemodes
end

So basically, the GamemodeManager:GetRandomGamemodes() function is suppose to go through the maps chosen. If the map is a Teams based map, then I need to pick a random gamemode out of the Teams based gamemodes. If the map is a FFA gamemode then it just picks FFA. Problem I have now is how I can link them together to send to the client?

My idea was ChosenData would look something like this

ChosenData = {
    Map1 = FFA,
    Map2 = TDM,
    Map3 = FFA
}

That way I can send those options to the client, and have them vote on it. But I don’t know how to add 2 separate tables to kinda form one

1 Like

Instead of using table.insert, do

ChosenGamemodes[v] = RandomGamemode

then the output of your function should be a table of desired format.

1 Like

Thought it worked, but can’t get it to go to client though

local ChosenData = GamemodeManager:GetRandomGamemodes(ChosenMaps)
	
ChooseMap:FireAllClients(ChosenData) -- ERROR

Cannot convert mixed or non-array tables: keys must be strings

ChosenMaps probably isn’t full of strings, but of Instances (the maps) then (?), in that case do

ChosenGamemodes[v.Name] = RandomGamemode