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

Changing Parents Of Parts ?

Asked by 9 years ago

Well I know some Very Very Very Very Basic scripting and I've learned this before but forgot it :/ It would really help if someone told me how..

3 answers

Log in to vote
2
Answered by 9 years ago

Ok, that would be the property Parent, it is used for different kinds of coding and is very useful, let me explain;

Workspace - Here is Workspace
    Script - And here is the Script

We can change the Scripts Parent by settings it a new Parent, by putting the code into the Script, or using the command bar, for example, lets put a few more things into the Workspace;

Workspace - Here is Workspace
    Script - Our Script
    Part - Now a new part

We can use this to our advantage, we could set the Parts Parent instead of Workspace, into the script! Lets do that;

local Part = game.Workspace.Part
Part.Parent = game.Workspace.Script -- I could've used 'script' instead of 'game.Workspace.Script', but if it is the Command bar, then you would've had to do it 'game.Workspace.Script'

As you'll see the Part is now inside of the script! Haha! But we can also sets its Parent back to Workspace like it was before? Shall we;

local Part = game.Workspace.Script.Part
Part.Parent = game.Workspace

And now the Parts Parent is Workspace again! There is another thing we could do, Clone the Part so that the original Part doesn't change. Lets show a demonstation;

local Part = game.Workspace.Part:Clone() --We are now cloning it :o
Part.Parent = game.Workspace

After doing that, the game will turn out something like this;

Workspace
    Script
    Part
    Part

Now there are two parts! Haha! And when we clone the Part, we can also rename it at the same time! Let me show you;

local Part = game.Workspace.Part:Clone()
Part.Parent = game.Workspace
Part.Name = "Part2"

Now the Workspace will look something like this;

Workspace
    Script
    Part
    Part2

Haha! We did it! We Cloned a Part, and changed its name! Haha! There is one other thing though, we could create a New Part out of thin air! Lets use a code;

local Part = Instance.new("Part") --We've made a Part :D
Part.Parent = game.Workspace --Now we parented it to Workspace :D

But, if we did something like this;

local Part = Instance.new("Part") --Yay! Another part :D
--Where the Parent D:

If we did something like that, the Part will not be in the Workspace, its Parent will then be nil, meaning null-and-void, valueless, or non-existent, it'll still be in the game, and will not be in the Workspace or anywhere, so we have make sure to add what its Parent is! Or else, we'll never see it again.. :o I hope this helped bro! :D

Ad
Log in to vote
0
Answered by 9 years ago

This is to easy. I mean to to to easy.

local brick = Instance.new("Part")
brick.Parent = game.Workspace
wait (2)
brick.Parent = game.Workspace.BrickStorageModel

i just made things up there, but thats basically what you could do, with BrickStorageModel being s model in workspace...

Log in to vote
0
Answered by
emite1000 335 Moderation Voter
9 years ago

A brick's parent will always be something. (Workspace.Part.Parent = Workspace)

Just change what that something is.

Workspace.Part.Parent = Workspace.Part2

Answer this question