Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I clone objects in order?

I was wondering how to clone objects in order from a model. I have 5 parts in a model, Part1, Part2, Part3, Part4, Part5. I want to clone those objects in order from Part1 ascending up to Part5 using GetChildren

local parts = game.ServerStorage.Parts:GetChildren()
local count = 0
for i = 1, #parts do
count = count + 1
parts[i]:Clone().Parent = game.Workspace
end

In that sort of manner, however right now they are cloning out of order.

1 answer

✓ Accepted answer

The simplest way to do this how you'd like it would be like this:

local parts = game.ServerStorage.Parts
for i = 1, #parts:GetChildren() do
	parts["Part"..i]:Clone().Parent = game.Workspace
end

The script will get the total number of parts in the model, and then go through them and use the 'i' variable to get the current part number it's on and concatenate it onto "Part".

Keep in mind that if you have any part in there that isn't like the others, the script will not work. There are ways to fix this, such as using an if statement, but that's for you to make, not me :)

1 comment

0

Thank you very much!

This discussion is preserved as it was. New answers, comments, and votes are closed.