Cloning problem

do anyone know how to make cloning inorder or Consecutively like
when the map is already use it will not going to use again
image

my problem is when the map is use it will going to use again in another round if u dont get it
ill make it simple


there is a round system and it will pick a map so banana has pick and after the round the banana got pick again


i want like only once the map pick and the other map will pick
script

local maps = game.ReplicatedStorage.Maps:GetChildren()

local rand = math.random(1,#maps)
	
	local map = maps[rand]:Clone()
	map.Parent = game.Workspace.Map

you could do something like

local maxmaps=#maps
local map=0

if map+1>maxmaps then map=1 else map+=1 end 
local selectedmap=maps[map]

this should cycle though the maps table and select a new map every round and after it reaches the last map on the table it resets to the first map and cycles again!

1 Like
local storage = game:GetService("ReplicatedStorage")
local maps = storage:WaitForChild("Maps"):GetChildren()
local rand = math.random(1, #maps)
local map = maps[rand]:Clone()
map.Parent = game.Workspace:WaitForChild("Map")

thats not the problem the problem is how can i do it in order

local storage = game:GetService("ReplicatedStorage")
local maps = storage:WaitForChild("Maps"):GetChildren()

for i, v in ipairs(maps) do
	--stuff
end

ipairs traverses over items within an array in the same order in which they are indexed.

1 Like

if you still need help with this you could have a function with that inside

local mapnumber=0

function PickMap()
if mapnumber+1>#maps then mapnumber=1 else mapnumber+=1 end 
local selectedmap=maps[mapnumber]

return selectedmap
end 

local map=PickMap()
local clonedmap=map:Clone()
clonedmap.Parent=workspace
local maxmaps = #maps
	local map = 0

	if map + 1 > maxmaps then 
		map = 1 
	else 
		map += 1 end 
	
	local selectedmap = maps[map]:Clone()
	selectedmap.Parent = game.Workspace.Map

is this what u mean

yep that should totally work! though the function i posted above seems to be more efficient since it uses less one variable

1 Like

Or you could just use the built-in function ipairs, since it does everything for you & with fewer checks.

1 Like

it didnt work it use again like when the map use it use again

the problem is with an for loop you’d have to keep the entire game code inside a loop which wouldn’t be a good idea at all

1 Like

It won’t work just use ipairs. All round-based games run in loops, that’s how they continue indefinitely. And using loops is fine.

local storage = game:GetService("ReplicatedStorage")
local maps = storage:WaitForChild("Maps"):GetChildren()
local round = 0
--round started
if round >= #maps then
	round = 0
end
round += 1
local roundMap = maps[round]

Simple yet effective logic, no loop required.

i tried urs and it didnt work

for i, v in ipairs(maps) do
		map = v:Clone()
		map.Parent = game.Workspace.Map
	end

it clone all the map

Of course it will clone all the maps, there’s no delay in there. It was just an example to show how to loop through your maps.

Add a task.wait(5) or whatever if you want to see the maps being cloned 1 after the other.

this one too didnt work it use again

It’s not ready to be used, it’s just a sample script for you to get ideas from.

1 Like

This should work.


local usedMaps = {}
local maps = game.ReplicatedStorage.Maps:GetChildren()

local rand = math.random(1,#maps)

local map = maps[rand]:Clone()
if not table.find(usedMaps,map) then
   table.insert(usedMaps,map)
   map.Parent = game.Workspace.Map
else
while wait() do
      local rand = math.random(1,#maps)

      local map = maps[rand]:Clone()
      if not table.find(usedMaps,map) then
        table.insert(usedMaps,map)
        map.Parent = game.Workspace.Map
        break
     end
end
end


2 Likes

thank u so much u save my game :))