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

Can someone help me with using "Parents" and "Children"?

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?

5 answers

✓ Accepted answer

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.

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.

1 comment

0

I really don't get it...

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.

Parents and Children

game.Workspace

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

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

1 comment

0

I love how they did the ducks in that picture though.

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