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

Cloning an Objects Children? [Script Included]

function CloneAllChildren(OldPar, NewPar)
for _,v in ipairs(OldPar) do
v:Clone().Parent = NewPar
end
end

CloneAllChildren(Workspace.Model, Workspace)

would that work like that? (even though am doing something else)...

3 answers

✓ Accepted answer

This is how you do it.

local Children = {} -- leave this empty

function Copy(Parent) -- Parent is the object that you want to get all of the child
	for i, object in pairs(Parent:GetChildren()) do
		table.insert(Children, object)
	end
end

function Paste(Parent) -- Parent here is the parent you want to paste to
	for i, child in ipairs(Children) do
		child.Parent = Parent
		table.remove(Children, i)
	end
end

Copy(Workspace.Model)
Paste(Workspace)

1 comment

0

k, thnx... I already found 1 but this was helpful :d

Um, I don't believe the variable "v" was necessarily designed as a part/model so it wouldn't be able to be "cloned." Therefore, it wouldn't work regardless. I also am not sure why "CloneAllChildren" is down on the bottom.

It's just pretty confusing. I'd say that script is both beyond repairing and nil.

1 comment

0

its the nam eof the function, and also, its a friend that gave me this script... so am looking for ways to clone an objects children... but I cant seem to find the answer :( :'(

People, CALM DOWN. It only takes a few lines goddamnit. e_o You dont need all of that 17 line stuff ._.

function CloneAllChildren(OldPar, NewPar)
	for i,v in pairs(OldPar:GetChildren()) do
		v:Clone().Parent = NewPar
		wait()
	end
end

CloneAllChildren(Workspace.Model, Workspace)

This'll work as long as the destinations are valid.

2 comments

0

wich ones do I change? is it just the bottom ones?

0

yes

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