Attempt to index nil with "Name"

I am trying to create a queue system for my game. However, the error on the title appears. Script is below

game.Players.PlayerAdded:Connect(function(player)
		player.Chatted:Connect(function(message)
			if player.UserId == game.CreatorId then
			if message:sub(1, 7) == "/queue " then
				local Gamemode = message:sub(8)
				table.insert(queue, Gamemode)
				print("Gamemode '" .. Gamemode .. "' has been added to the queue.")
			end
			end
		end)
	end)


local queue = {}
	local ChosenMap = Maps[math.random(1, #Maps)]
	local MapClone = ChosenMap:Clone()

	wait(IntermissionTime.Value)

	function selectRandomGamemode()
		Gamemodes = {
			["Gamemode1"] = 0.1,
			["Gamemode2"] = 0.1,
			["Gamemode3"] = 0.1
		}
		local Weight = 0
		for _, Chance in pairs(Gamemodes) do
			Weight += (Chance * 10)
		end
		local ranNumber = math.random(1, Weight)
		Weight = 0
		for Gamemode, Chance in pairs(Gamemodes) do
			Weight += (Chance * 10)
				if Weight >= ranNumber then
				return
				end
				end
			end	
				
	function getNextGamemode()
		if next(queue) then
			local Gamemode = table.remove(queue, 1)
			print("The next gamemode from the queue is: " .. Gamemode.Name)
			return Gamemode
		else
			return selectRandomGamemode()
		end
	end

	 Gamemode = getNextGamemode()

	MapClone.Parent = game.Workspace.Map
	MapClone:MakeJoints()
	wait(3)	
	for i, v in pairs(game.Players:GetPlayers()) do
		v.Character:FindFirstChild("HumanoidRootPart")
		if v.Character.HumanoidRootPart == false then
		return else
		v.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-430, 50, -430))
	end
	end
	
if Gamemode.Name == "Gamemode1" then
--insert game code here--
elseif Gamemode.Name == "Gamemode2" then
--insert game code here--
elseif Gamemode.Name == "Gamemode3" then
--insert game code here--
end

This isn’t all the code, but this is the important part

if Gamemode.Name == “Gamemode1” then

This line here is the part that breaks. I don’t know why or whats going on.

It means that GameMode isn’t defined.

Its hard to see the whole script on mobile but you should just add a check to determine if GameMode is nil or not before attempting to find its name.

in selectRandomGamemode() you are returning nothing:

I think it’s supposed to be return Gamemode

Can we see what it prints from print("The next gamemode from the queue is: " .. Gamemode.Name) ? I think the problem here is that you can’t just get index of dictionary by reaching .Name, hence undefined. To get a table’s index name you need to do

for i,v in pairs(Gamemode) do
	local gamemodeName = i --There is your gamemode name.
	
	break --To get only first gamemode index
end