More effective way to do what i'm trying to do?

local function Choose()
		local Map
		local GameModes = {"Murder Mystery", "Prop Hunt", "THunt"}	
		local Maps = {}
		local GameChoice = math.random(1, #GameModes) --- Ehh getting a random choice
		for _, MapValues in ipairs(game.ServerStorage.GameData[GameModes[GameChoice]].Maps:GetChildren()) do -- for loop getting all of the chosen gamemode
			table.insert(Maps, #Maps+1, MapValues) -- Inserts the values, Dont feel like writing out the maps
			local MapChoice = math.random(1, #Maps) -- orders the map choics
			Map = Maps[MapChoice] -- Gets map choice
			--print(Map)
		end
		return GameModes[GameChoice], Map
	end

What I did here works but is there a betterway to do this?

This won’t be specific to your use case, but from the looks of it you are trying to pick a random map from a list of maps.

local function pick()
	local maps = location:GetChildren()
	local selected = maps[math.random(1,#maps)]
	return selected
end

local result = pick() -- Will be the map Instance

After further review of the post:
This looks like how I’d select it. At first glance I can’t see a better way to do it. Only changes I have there is I have compiled them into a little smaller pieces and used Instances instead of values or whatnot.

1 Like

Wow, I didn’t know I could do that. Thanks!

Another question, What is the most effective way to make sure a player was not chosen twice?

if Player1 == Player2 then
			print("Same Player")
local Player2 = Players[math.random(1, #Players)]
		else
			print("Not Same")
			return GameMode, Map, Player1, Player2
		end

This is what I have now

local lastPlayer = nil

function stuff()
	local selected = however player is selected
	if selected == lastPlayer then
		-- Redo. Maybe use a function for picking the player so you don't copy the same code
	else
		-- Whatever needs doing
		lastPlayer = selected
	end
end
function MainModule.SetupGame() -- Game Setup only if players are true
		local GameMode, Map = ChooseGame() -- Player1/Player 2 may depend on the gamemode TBD
		local Player1, Player2 = ChoosePlayer()
		print(GameMode, Map, Player1, Player2)
		if Player1 == Player2 then
			Player2 = nil
			ChoosePlayer()
		else
			Player2 = Player2
			Player1 = Player1
		end
		return true
	end

Like this?

Why set Player1 to itself and Player2 to itself?
You’ll need to reassign Player1 and Player2 after running ChoosePlayer again and then check on top of that or it will just return true.