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

How do you give a cloned object a parent?

Can we go: game.Workspace.Lighting.Sword:Clone() sword.Parent = sword.Parent.Starterback

I know we can't just go like that I need some help on it.

2 answers

Instance:Clone() returns a reference to the cloned instance, so just use that:

local ClonedInstance = Instance:Clone()
ClonedInstance.Parent = TargetParent

There are two ways you could go about it

The first is doing it all without creating a variable for the object. This would mean you can't make any changes after parenting the object

game.Workspace.Lighting.Sword:Clone() .Parent = sword.Parent.Starterback

The second way is to assign the cloned object to a variable, which would allow you to make changes even after parenting the object

local clone = game.Workspace.Lighting.Sword:Clone()
clone.Parent = sword.Parent.Starterback
clone.Name = "Woah I can still change this!"

As you can see in the second example we were able to change the name of the cloned object after parenting it

Hope this helped!

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