# How to prevent script on cloning the same map

I have a random map choser that puts it in a placeholder so the players can vote what map they want to have, the problem is it usually clones the same map 2 times and the payers can see that the map vote have the same map in them

script:
``````local Vcount1 = game:GetService("ReplicatedStorage").RoundSystemEvents:WaitForChild("Map1Votes")
local Maps = game:GetService("ReplicatedStorage").Maps:GetChildren()

local RMap1 = Maps[math.random(1, #Maps)]
local RMap2 = Maps[math.random(1, #Maps)]
local RMap3 = Maps[math.random(1, #Maps)]

RMap1:Clone().Parent = Vcount1
RMap2:Clone().Parent = Vcount2
RMap3:Clone().Parent = Vcount3
``````

You could create a variable that stores the last chosen map and with using a `repeat until` loop you can check if your randomly chosen map is not the last one (this may not be the best method, but for time being it is the fastest and easiest I know of).

Make a list of all the maps, shuffle it, and choose the first three:

``````local function ShuffleInPlace(t)
for i = #t, 2, -1 do
local j = math.random(i)
t[i], t[j] = t[j], t[i]
end
end

-- ...

local Maps = game:GetService("ReplicatedStorage").Maps:GetChildren()

ShuffleInPlace(Maps)

local RMap1 = Maps[1]
local RMap2 = Maps[2]
local RMap3 = Maps[3]

-- ...
``````

Edit: Actually you just have to shuffle the first three elements, so you can do:

``````function ShuffleN(t, n)
local l = #t
for i = 1, n do
local j = math.random(i, l)
t[i], t[j] = t[j], t[i]
end
end
local Maps = game:GetService("ReplicatedStorage").Maps:GetChildren()

ShuffleN(Maps, 3)

local RMap1 = Maps[1]
local RMap2 = Maps[2]
local RMap3 = Maps[3]
``````
1 Like

This most defiently does not work, but could be a decent base for you ect. (Iām not cut out for this stuff )

``````local Maps = game:GetService("ReplicatedStorage").Maps:GetChildren()
local lastChosenMap = nil
local randomX = nil
local function onRandom()
randomX = Maps[math.random(1, #Maps)]
end
for _,  v ipairs(Maps:GetChildren) do
onRandom()
repeat
onRandom()
wait(1)
until randomX ~= lastChosenMap
if randomX ~= lastChosenMap then
randomX:Clone()
end
end
``````