Random GameMode

Need a away to pick a random game mode for my round system
eg.Murder Mystery,Spleef,Incognito

Use math.random and a table with the game modes in

no im wondering how the function would work

anyoneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

local gamemodelist = {
"Normal",
"Evil",
"Impossible"
}

local gamemode = math.random(1, #gamemodelist)

thank you for giving me and idea :cityscape: :cityscape:

So I have done this but in the murder game mode im getting confused on how to make sure the murder and sheriff arent the same
eg. local RandomMurder = Players:GetPlayerByUserId(InGameTable[math.random(1,#InGameTable)])
local Sheriff = Players:GetPlayerByUserId(InGameTable[math.random(1,#InGameTable)])

if RandomMurder  == Sheriff then
   --Do reroll murder or sheriff here
end

or just remove his id from the array

Thanks for the help..zzzzzzzzzzzzzzzz

but what happens if its the same again?

like FireStrykerAzul said : You can remove sheriff/murder from array then reroll then no need worry about it happen again

Iv just tested my round system and for some reason only 1 player is getting tped would you know why?
local RoundTime = 100
local IntermissionTime = 9

local MinPlayers = 2

local InGameTable = {}
local InLobbyTable = {}

local gamemodelist = {
“Sword Fight”,
–“Murder”,
–“Incognito”
}

local Players = game:GetService(“Players”)
local ServerStorage = game:GetService(“ServerStorage”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

local Lobby = game.Workspace.Baseplate

local ChosenMap
local Maps = ServerStorage.Maps:GetChildren()
local function RandomMap()
local RanMap = Maps[math.random(1,#Maps)]:Clone()
RanMap.Parent = workspace
print(RanMap)
ChosenMap = RanMap
end

Players.PlayerAdded:Connect(function(player)
table.insert(InLobbyTable,player.UserId)
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild(“Humanoid”)
Humanoid.Died:Connect(function()
table.remove(InGameTable,table.find(InGameTable,player.UserId))
table.insert(InLobbyTable,player.UserId)
end)
end)

Players.PlayerRemoving:Connect(function(player)
table.remove(InLobbyTable,table.find(InLobbyTable,player.UserId))
local CouldBeINGame = table.find(InGameTable,player.UserId)
if CouldBeINGame then
table.remove(InGameTable,CouldBeINGame)
end
end)

local function CheckForPlayers()
if #Players:GetPlayers() < MinPlayers then
warn(“Not Enough Players”)
repeat wait(1) until #Players:GetPlayers() >= MinPlayers
end
end

local function StartGame()
RandomMap()
ChosenMap.Parent = workspace
local gamemode = gamemodelist[math.random(1,#gamemodelist)]

if gamemode == “Murder” then
for i,plr in pairs(InLobbyTable) do
local player = Players:GetPlayerByUserId(plr)

		local Character = player.Character
		local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
		if HumanoidRootPart then
			local Spawns = ChosenMap.Spawns:GetChildren()
			local RandomSpawn = Spawns[math.random(1,#Spawns)]
			HumanoidRootPart.CFrame = RandomSpawn.CFrame
			table.remove(InLobbyTable,table.find(InLobbyTable,plr))
			table.insert(InGameTable,plr)
			print("Payer Name: "..player.Name)
			warn("Game Started")
			print(InLobbyTable)
			print(InGameTable)
			print(gamemode)
		end

	end
	local RandomMurder = Players:GetPlayerByUserId(InGameTable[math.random(1,#InGameTable)])
	local Sheriff = Players:GetPlayerByUserId(InGameTable[math.random(1,#InGameTable)])
	if RandomMurder == Sheriff then
		Sheriff = Players:GetPlayerByUserId(InGameTable[math.random(1,#InGameTable)])
		print(Sheriff)
	end

end

if gamemode == "Sword Fight" then
	for i,plr in pairs(InLobbyTable) do
		local player = Players:GetPlayerByUserId(plr)

		local Character = player.Character
		local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
		if HumanoidRootPart then
			local Sword = game.ServerStorage.ClassicSword:Clone()
			local Spawns = ChosenMap.Spawns:GetChildren()
			local RandomSpawn = Spawns[math.random(1,#Spawns)]
			HumanoidRootPart.CFrame = RandomSpawn.CFrame
			table.remove(InLobbyTable,table.find(InLobbyTable,plr))
			table.insert(InGameTable,plr)
			print("Payer Name: "..player.Name)
			warn("Game Started")
			print(InLobbyTable)
			print(InGameTable)
			print(gamemode)
			local BackPack = player.Backpack
			Sword.Parent = BackPack
		end

	end
end

if gamemode == "Incognito" then
	for i,plr in pairs(InLobbyTable) do
		local player = Players:GetPlayerByUserId(plr)

		local Character = player.Character
		local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
		if HumanoidRootPart then
			local Spawns = ChosenMap.Spawns:GetChildren()
			local RandomSpawn = Spawns[math.random(1,#Spawns)]
			HumanoidRootPart.CFrame = RandomSpawn.CFrame
			table.remove(InLobbyTable,table.find(InLobbyTable,plr))
			table.insert(InGameTable,plr)
			print("Payer Name: "..player.Name)
			warn("Game Started")
			print(InLobbyTable)
			print(InGameTable)
			print(gamemode)
		end

	end
end

end

local function EndGame()

for i,plr in pairs(InGameTable) do
	local player = Players:GetPlayerByUserId(plr)
	print("Player Name: "..player.Name)
	local Character = player.Character
	local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	if HumanoidRootPart then
		HumanoidRootPart.CFrame = Lobby.SpawnLocation.CFrame + Vector3.new(0,5,0)
		table.remove(InGameTable,table.find(InGameTable,plr))
		table.insert(InLobbyTable,plr)
		print("Payer Name: "..player.Name)
		warn("Game Ended")
		print(InGameTable)
		print(InLobbyTable)
		local BackPack = player.Backpack
		BackPack:ClearAllChildren()
		for i,tools in pairs(Character:GetChildren()) do
			if tools:IsA("Tool") then
				tools:Destroy()
			end
		end
	end

end

ChosenMap.Parent = nil

end

while true do
CheckForPlayers()
for i = IntermissionTime,1,-1 do
print(i)
CheckForPlayers()

	task.wait(1)
end

StartGame()



for i = RoundTime,1,-1 do
	print(i)

	task.wait(1)
	
	if #InGameTable == 1 then
		local Winner = Players:GetPlayerByUserId(InGameTable[1])
		print(Winner.Name.." has won")
		Winner.leaderstats.Dubs.Value = Winner.leaderstats.Dubs.Value +1
		task.wait(1)
		break
	end
	if #InGameTable == 0 then
		warn("Everyone Lost")
		task.wait(1)
		break
	end
end	

EndGame()

end

Fixed Version

local IntermissionTime = 9

local MinPlayers = 2

local InGameTable = {}
local InLobbyTable = {}

local gamemodelist = {
	"Sword Fight",
	--"Murder",
	--"Incognito"
}




local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")


local Lobby = game.Workspace.Baseplate

local ChosenMap
local Maps = ServerStorage.Maps:GetChildren()
local function RandomMap()
	local RanMap = Maps[math.random(1,#Maps)]:Clone()
	RanMap.Parent = workspace
	print(RanMap)
	ChosenMap = RanMap
end

Players.PlayerAdded:Connect(function(player)
	table.insert(InLobbyTable,player.UserId)
	local Character = player.Character or player.CharacterAdded:Wait()
	local Humanoid = Character:WaitForChild("Humanoid")
	Humanoid.Died:Connect(function()
		table.remove(InGameTable,table.find(InGameTable,player.UserId))
		table.insert(InLobbyTable,player.UserId)
	end)
end)

Players.PlayerRemoving:Connect(function(player)
	table.remove(InLobbyTable,table.find(InLobbyTable,player.UserId))
	local CouldBeINGame = table.find(InGameTable,player.UserId)
	if CouldBeINGame then
		table.remove(InGameTable,CouldBeINGame)
	end
end)

local function CheckForPlayers()
	if #Players:GetPlayers() < MinPlayers then
		warn("Not Enough Players")
		repeat wait(1) until #Players:GetPlayers() >= MinPlayers
	end
end

local function StartGame()
	RandomMap()
	ChosenMap.Parent = workspace
local gamemode = gamemodelist[math.random(1,#gamemodelist)]



if gamemode == "Murder" then
		for i,plr in pairs(InLobbyTable) do
			local player = Players:GetPlayerByUserId(plr)

			local Character = player.Character
			local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
			if HumanoidRootPart then
				local Spawns = ChosenMap.Spawns:GetChildren()
				local RandomSpawn = Spawns[math.random(1,#Spawns)]
				HumanoidRootPart.CFrame = RandomSpawn.CFrame
				table.remove(InLobbyTable,table.find(InLobbyTable,plr))
				table.insert(InGameTable,plr)
				print("Payer Name: "..player.Name)
				warn("Game Started")
				print(InLobbyTable)
				print(InGameTable)
				print(gamemode)
			end

		end
		local RandomMurder = Players:GetPlayerByUserId(InGameTable[math.random(1,#InGameTable)])
		local Sheriff = Players:GetPlayerByUserId(InGameTable[math.random(1,#InGameTable)])
		if RandomMurder == Sheriff then
			Sheriff = Players:GetPlayerByUserId(InGameTable[math.random(1,#InGameTable)])
			print(Sheriff)
		end
	
end
	

	if gamemode == "Sword Fight" then
		for i,plr in pairs(InLobbyTable) do
			local player = Players:GetPlayerByUserId(plr)

			local Character = player.Character
			local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
			if HumanoidRootPart then
				local Sword = game.ServerStorage.ClassicSword:Clone()
				local Spawns = ChosenMap.Spawns:GetChildren()
				local RandomSpawn = Spawns[math.random(1,#Spawns)]
				HumanoidRootPart.CFrame = RandomSpawn.CFrame
				table.remove(InLobbyTable,table.find(InLobbyTable,plr))
				table.insert(InGameTable,plr)
				print("Payer Name: "..player.Name)
				warn("Game Started")
				print(InLobbyTable)
				print(InGameTable)
				print(gamemode)
				local BackPack = player.Backpack
				Sword.Parent = BackPack
			end

		end
	end

	if gamemode == "Incognito" then
		for i,plr in pairs(InLobbyTable) do
			local player = Players:GetPlayerByUserId(plr)

			local Character = player.Character
			local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
			if HumanoidRootPart then
				local Spawns = ChosenMap.Spawns:GetChildren()
				local RandomSpawn = Spawns[math.random(1,#Spawns)]
				HumanoidRootPart.CFrame = RandomSpawn.CFrame
				table.remove(InLobbyTable,table.find(InLobbyTable,plr))
				table.insert(InGameTable,plr)
				print("Payer Name: "..player.Name)
				warn("Game Started")
				print(InLobbyTable)
				print(InGameTable)
				print(gamemode)
			end

		end
	end
	
	
	
	
	
	
end

local function EndGame()
	
	for i,plr in pairs(InGameTable) do
		local player = Players:GetPlayerByUserId(plr)
		print("Player Name: "..player.Name)
		local Character = player.Character
		local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
		if HumanoidRootPart then
			HumanoidRootPart.CFrame = Lobby.SpawnLocation.CFrame + Vector3.new(0,5,0)
			table.remove(InGameTable,table.find(InGameTable,plr))
			table.insert(InLobbyTable,plr)
			print("Payer Name: "..player.Name)
			warn("Game Ended")
			print(InGameTable)
			print(InLobbyTable)
			local BackPack = player.Backpack
			BackPack:ClearAllChildren()
			for i,tools in pairs(Character:GetChildren()) do
				if tools:IsA("Tool") then
					tools:Destroy()
				end
			end
		end

	end
	
	ChosenMap.Parent = nil
	

	
	
	
	
	
	
	
end



while true do
	CheckForPlayers()
	for i = IntermissionTime,1,-1 do
		print(i)
		CheckForPlayers()
		
		task.wait(1)
	end
	
	StartGame()
	
	
	
	for i = RoundTime,1,-1 do
		print(i)

		task.wait(1)
		
		if #InGameTable == 1 then
			local Winner = Players:GetPlayerByUserId(InGameTable[1])
			print(Winner.Name.." has won")
			Winner.leaderstats.Dubs.Value = Winner.leaderstats.Dubs.Value +1
			task.wait(1)
			break
		end
		if #InGameTable == 0 then
			warn("Everyone Lost")
			task.wait(1)
			break
		end
	end	
	
	EndGame()
	
	
end```