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

How to clone an object into multiple children?

I'm having trouble figuring this one out, I cannot find anything online about it either. The following script just gives me an error. Help would be appriciated.

local partiCln = script.Parent.ParticleEmitter:Clone()
local scriptCln = script.Parent.Breakdown:Clone()

partiCln.Parent = script.Parent:GetChildren()
scriptCln.Parent = script.Parent:GetChildren()

1 answer

✓ Accepted answer

That is NOT how you use GetChildren(). Here's an example of what you want.

local model = game.Workspace:WaitForChild("Model")

for _,v in pairs(model:GetChildren()) do-- set this to your model
	if v:IsA("BasePart") then -- remove this and the 'end' if u dont want the object clone to a part only
		local objectClone = game.Workspace:WaitForChild("Object")
		objectClone.Parent = v
	end
end

Basically, GetChildren() gets a table of childrens inside a model. You use a for loop to itterate it.

Note: Click view source by hovering over the code and clicking it in the upper right corner. You use it to copy the code WAY easier.

4 comments

0

This is JUST AN EXAMPLE. You need to set up the objectClone and the model.

0

OOP you bet me to it

0

Thank you so much, it works perfectly!

1

If it helps, PLEASE accept it!

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