It randomly selects one, and brings the one to workspace, on the first round there is always two maps, and the next rounds, there is occasionally one, or two.
function getRandomMap()
local gameMaps = game.Lighting.Maps:GetChildren()
local randomMap = gameMaps[math.random(1, #gameMaps)]
return randomMap
end
function reshuffleteams(teams)
local players = game.Players:GetPlayers()
local t = true
for i = 1,#players do
if t == true then
players[i].TeamColor = game.Teams[teams[1]].TeamColor
else
players[i].TeamColor = game.Teams[teams[2]].TeamColor
end
t = not t
end
end
function respawnnoobs()
local P = game.Players:GetPlayers()
for i = 1,#P do
P[i]:LoadCharacter()
end
end
function startGame()
if game.Players.NumPlayers >= 2 then
gameStarted = true
Workspace.RedTeam.Value = 1
Workspace.BlueTeam.Value = 1
local gameMap = getRandomMap()
wait(3)
local mapClone = gameMap:clone()
mapClone.Parent = workspace
mapClone.Name = "Map"
reshuffleteams({"Goodish","Evilish"})
respawnnoobs()
timer = 0
repeat wait(1)
timer = timer+1
until
Workspace.BlueTeam.Value==0 or Workspace.RedTeam.Value==0 or timer==45
if Workspace.BlueTeam.Value==0 then
h=Instance.new("Message", Workspace)
h.Text="RedTeam has won! Awarding Points.."
elseif
Workspace.RedTeam.Value==0 then
h=Instance.new("Message", Workspace)
h.Text="BlueTeam has won! Awarding Points.."
else
h=Instance.new("Message", Workspace)
h.Text="Timer has run out! Tie. No Points Awarded. D:"
end
wait(3)
workspace:FindFirstChild("Map"):Destroy()
reshuffleteams({"Lobby","Lobby"})
respawnnoobs()
workspace:FindFirstChild("Message"):Destroy()
wait(30) ------------(intermission)
startGame()
else
gameStarted = false
end
end
game.Players.PlayerAdded:connect(function()
wait(10)
if game.Players.NumPlayers<2 and gameStarted == false then
h=Instance.new("Message", Workspace)
h.Text="Need more then 2 players to start"
game:GetService("Debris"):AddItem(h, 5) --Remove the message after 5 seconds.
elseif game.Players.NumPlayers >= 2 then
startGame()
end
end)
Why does it make two once in a while? Also any general improvement I could make to this script?

1 comment
1, 35, 66 are the lines that deal with the maps.