Random map selector, not selecting a map

I am trying to make a random map selector that would select the same map twice. The map wont clone, or parent to workspace. I’ve gone on a few discord servers to get help

local currentMap = 1
local maps = game.ReplicatedStorage.Stages:GetChildren()

local function shuffle(tbl)
	for index in ipairs(tbl) do
		local ranIdx = math.random(#tbl)
		tbl[index], tbl[ranIdx] = tbl[ranIdx], tbl[index]
	end
end


local function chooseMap()
	currentMap += 1
	if currentMap > #maps then
		currentMap = 1
		shuffle(maps)
		map = maps[currentMap]:Clone()
	end
end

1 Like

You’ll need to move map = maps[currentMap]:Clone() out side of the if statement, because it’ll only be called once, when the currentMap overflows.