I need to clone all the contents of a folder!

I need help figuring out how to clone all the contents of a folder.

  1. What do you want to achieve? I want to make a item saving system after buying an item in the shop.

  2. What is the issue? I cannot figure out how to do this.

  3. What solutions have you tried so far? I have done many google searches and Developer Forum searches.

Here is my code:

local ownedTools = script.Parent.Parent.OwnedTools
game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local clonedTools = ownedTools.Children:Clone()
		clonedTools.Parent = script.Parent.Parent.Backpack
	end)
end)

I would also like to say that I am not good with for loops. I need to learn up!

Thank you if you can help!

You can’t :Clone() a table, and .Children would only be a reference to a single child named “Children” explicitly, but you can iterate a table and clone everything individually. I find it hard to believe you couldn’t find how to iterate a model’s children searching on dev forums though…

for _, tool in pairs(ownedTools:GetChildren()) do
    local clone = tool:Clone()
    clone.Parent = script.Parent.Parent.Backpack
end