Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you give a cloned object a parent?

Asked by 6 years ago

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

Log in to vote
1
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

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

local ClonedInstance = Instance:Clone()
ClonedInstance.Parent = TargetParent
Ad
Log in to vote
1
Answered by 6 years ago

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!

Answer this question