✓ Accepted answer
I believe that the top or bottom of your while true do loop would be suitable for the changing of maps. I think the top would suit best.
I don't know where your maps are located, so I'll be using (for these examples) Maps as a the path to a folder/model that would hold all the maps you want to switch.
Now, we could go about selection of a new map at random, or by order. I'll cover both, in case you wish to experiment.
local Maps
local function GetRandomMap(maps)
maps = maps or Maps
local children = maps:GetChildren()
return children[math.random(#children)]
end
local last_map = 0
local function GetOrderedMap(maps)
maps = maps or Maps
last_map = (last_map or 0) + 1
local children = maps:GetChildren()
if last_map > #children then
last_map = 1
end
return children[last_map]
end
Now that the selection process is complete, we would need a method of switching maps. I am going to try my best to explain the process.
local CurrentMap = nil
local function SwtichMap(map)
if map and typeof(map) == "Instance" then
if CurrentMap then
CurrentMap:Destroy()
end
local NewMap = map:Clone()
if NewMap then
NewMap.Parent = workspace
CurrentMap = NewMap
return NewMap
end
end
end
Now we can switch out a map like this. There are multiple different ways you could switch out a map, this is just one of many.
local map_selection = GetRandomMap()
while not map_selection do
map_selection = GetRandomMap() or GetOrderedMap()
end
repeat
CurrentMap = SwitchMap(map_selection)
until CurrentMap
Now we got everything defined. We can begin placing code where it belongs. This is what I'd do
local GameManager = require(script.GameManager)
GameManager:Initialize()
local Maps
local last_map = 0
local CurrentMap = nil
local function GetRandomMap(maps)
maps = maps or Maps
local children = maps:GetChildren()
return children[math.random(#children)]
end
local function GetOrderedMap(maps)
maps = maps or Maps
last_map = (last_map or 0) + 1
local children = maps:GetChildren()
if last_map > #children then
last_map = 1
end
return children[last_map]
end
local function SwtichMap(map)
if map and typeof(map) == "Instance" then
if CurrentMap then
CurrentMap:Destroy()
end
local NewMap = map:Clone()
if NewMap then
NewMap.Parent = workspace
CurrentMap = NewMap
return NewMap
end
end
end
while true do
local map_selection = GetRandomMap()
while not map_selection do
map_selection = GetRandomMap() or GetOrderedMap()
end
repeat
CurrentMap = SwitchMap(map_selection)
until CurrentMap
repeat
GameManager:RunIntermission()
until GameManager:GameReady()
GameManager:StopIntermission()
GameManager:StartRound()
repeat
GameManager:Update()
wait()
until GameManager:RoundOver()
GameManager:RoundCleanup()
end
2 comments
Thank you very much for your help
Happy to help.