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

Can someone help me with using "Parents" and "Children"? [closed]

Asked by 10 years ago

I want to know how to use these to my advantage. I also want to put them in a script and other such things. Anyone care helping?

Locked by SanityMan and TheMyrco

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

5 answers

Log in to vote
4
Answered by
SanityMan 239 Moderation Voter
10 years ago

Say that in my ROBLOX Studio Explorer Window I see the following:

Workspace
    Terrain
    Camera
    YourBasePlate
    ButtonBrick
        YourButtonScript
Players
Lighting
ReplicatedStorage
ServerScriptStorage
StarterGui
StarterPack
Debris
Soundscape

Note: This was formatted in the form of a script to make visible the paths of Parents and Children

All or these are descendants of the "game". Things on this directory like "Workspace" and "Players" are direct children of "game". It is like one big family. "Workspace" is the child of "game", and "Terrain" is the child of "Workspace". Your building parts and your scripts will usually be in the "Workspace" family as you can see with the brick named "YourBasePlate". If you wanted to make a button brick, you could have your "ButtonBrick" in the family of "Workspace", and have a script to activate in the family of "ButtonBrick". You might make a button script like the following:

button = script.Parent
brick.Touched:connect(function(part)
    print("I've been touched!")
end)

In the first line, the variable "button" is defined. It tells the script that "button" is the script's Parent, which in this case happens to be "ButtonBrick". The second line tells the script that if the brick is touched, trigger the function. If the function is triggered, the script will print "I've been touched!" to the output window in ROBLOX Studio. The final line closes the function, and thus finishes off the event.

tl;dr: Parents and Children act like a big family tree. You can refer to the Parent of an object with the ".Parent", or even go further up the hierarchy with something like "script.Parent.Parent". Parents and Children just are the way of organizing objects and services in the "game" directory.

Ad
Log in to vote
2
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago

Objects in Roblox's game environment are represented as subtables with 'Parent' as a certain value in the subtable which refers to the object it is a child of. Objects are indexed hierarchically.

0
I really don't get it... Luigi7381 25 — 10y
Log in to vote
1
Answered by 10 years ago

Ok so Parents and Children are pretty easy. The Parent is like the Parent of the Child. If you have a TextButton inside a SscreenGui, then the TextButton is the "Child" of the ScreenGui which is the "Parent" to the text button.

eg.

script.Parent.Text = "Hello"

This script inside a TextButton will look at the parent of the script, which is the TextButton, then look at its properties for Text, then make it say "Hello"

Make sure to rate up for me and accept the answer for everyone else.

Log in to vote
0
Answered by 10 years ago

Try looking at the upper half of this picture. Ignore the bottom half, that is talking about a different programming language.

0
I love how they did the ducks in that picture though. DiamondBladee 135 — 10y
Log in to vote
0
Answered by 10 years ago

Parents and Children

game.Workspace

"game" is "Workspace's" Parent. "Workspace" is "game's" Child.