Cloning folder chunks one by one

Basically,
in a previous draft I asked on how would I copy a children in a folder one by one with a wait(1) by each clone.
These was the code:

local c1 = game.Workspace.Folder:GetChildren()

for index, chunk in c1 do
local clonedchunk = chunk:Clone()
clonedchunk.Parent = workspace
end

Now, sometimes it clones more than just one time the same child. How do I fix that

3 Likes

Are you sure it is doing this? Upon inspection, I see no issues with the code that you have provided. perhaps there are duplicates stored inside the folder itself?

1 Like

Sometimes it duplicates it and then does it a couple more times

1 Like

You could add the name of the item to a table and check if it has been cloned

The bug is somewhere else. Try checking if there’re duplicate chunks in the folder itself.

Also your code has no wait in it, and without yielding it will cause a lag spike as if you loaded everything at once.

I have a theory. What if your cloned objects are being included in the loop?

Doesnt seem like…
An event is fired when a part is touched, wich has debounce so its not possible to bug that
Then, the server detects the event and changes the cloned chunks
Code:

for index, chunk in c1 do
	if not chunk:FindFirstChild("NotCopiable") then
		if chunk.Name ~= "NonCopiableChunk" then
		local nval = Instance.new("BoolValue")
			nval.Name = "NotCopiable"
	local clonedchunk = chunk:Clone()
				clonedchunk.Name = "NonCopiableChunk"
	nval.Parent = clonedchunk
	clonedchunk.Parent = workspace:WaitForChild("ChunkFolder")
	wait(1)
	end
	end
end

I placed a print and sometimes it prints two or more times

Yes it is. Read previous reply.