Learn Scripting
How to script in Roblox Studio
How to script in Roblox Studio
Referencing a Part
Referencing a Part
To be able to change something about a part or object in your game you need to be able to reference that part. You can think of this like moving through a tree.
To be able to change something about a part or object in your game you need to be able to reference that part. You can think of this like moving through a tree.
The biggest part of the tree is the trunk. From the trunk there are many different large branches that you can navigate to, and on each large branch there are many small branch that eventually end in a leaf.
The biggest part of the tree is the trunk. From the trunk there are many different large branches that you can navigate to, and on each large branch there are many small branch that eventually end in a leaf.
I thought I came here to learn Roblox Studio. . .
I thought I came here to learn Roblox Studio. . .
Well when trying to reference a part in a script you can use the same idea as trying to reference a particular leaf on a tree. Start with the biggest part then move to smaller and smaller parts until you get to the part you want!
Well when trying to reference a part in a script you can use the same idea as trying to reference a particular leaf on a tree. Start with the biggest part then move to smaller and smaller parts until you get to the part you want!
In Roblox Studio the largest section is called "game"
In Roblox Studio the largest section is called "game"
After "game" the next largest sections are found in the explorer menu
After "game" the next largest sections are found in the explorer menu
Explorer Menu
Explorer Menu
Workspace Section
Workspace Section
When ever you add a part into the game it goes into the workspace section by default
When ever you add a part into the game it goes into the workspace section by default
So if I wanted to reference a part that I just added into the game it would look something like this:
So if I wanted to reference a part that I just added into the game it would look something like this:
game.Workspace.Part
game.Workspace.Part
Starting with the biggest section and moving to smaller sections until you get to the object you want
Starting with the biggest section and moving to smaller sections until you get to the object you want
Another Example
Another Example
If I wanted to reference the part labeled "ThisOne" how would I do it?
If I wanted to reference the part labeled "ThisOne" how would I do it?
Try it yourself then check your answer below!
Try it yourself then check your answer below!
Reveal Answer
Reveal Answer
game.Workspace.Model1.Model2.ThisOne
game.Workspace.Model1.Model2.ThisOne
Adding a Script
Adding a Script
Programming in Roblox Studio works by adding what are called scripts to objects that you want code for.
Programming in Roblox Studio works by adding what are called scripts to objects that you want code for.
To add a script to a part:
To add a script to a part:
1. Find that part in the explorer menu
1. Find that part in the explorer menu
2. Click on it
2. Click on it
3. Click the + sign next to the name
3. Click the + sign next to the name
4. Type script in the search bar
4. Type script in the search bar
5. Click on script
5. Click on script
After you do that you will now have a new script that you can begin write you code on!
After you do that you will now have a new script that you can begin write you code on!
Varaibles
Varaibles
Variables in programming are used to store information.
Variables in programming are used to store information.
In Roblox Studio variables are especially useful for storing part references. For example to talk about the part above I would have to write
In Roblox Studio variables are especially useful for storing part references. For example to talk about the part above I would have to write
game.Workspace.Part
game.Workspace.Part
Then if i wanted to change one of its properties then I would write something like this
Then if i wanted to change one of its properties then I would write something like this
game.Workspace.Part.Transparency = 1
game.Workspace.Part.Transparency = 1
Now this may not seem so bad if this is the only thing I am doing with this part, however as you begin writing longer and more complex programs writing out the entire part reference everything you want to make a change to it will become tedious.
Now this may not seem so bad if this is the only thing I am doing with this part, however as you begin writing longer and more complex programs writing out the entire part reference everything you want to make a change to it will become tedious.
Instead we can use a variable to "store a part" which makes it much easier to talk about later on in the script
Instead we can use a variable to "store a part" which makes it much easier to talk about later on in the script
Hopefully from the example above, you can begin to use the usefulness of variables in scripts!
Hopefully from the example above, you can begin to use the usefulness of variables in scripts!
Changing Properties of Parts
Changing Properties of Parts
Setting a New Value
Setting a New Value
Some part properties can be change by simply setting that property equal to a new number. For example:
Some part properties can be change by simply setting that property equal to a new number. For example:
Setting a New Vector
Setting a New Vector
Other properties can be changed by giving the property a new set of numbers called a vector. Examples include:
Other properties can be changed by giving the property a new set of numbers called a vector. Examples include:
Changing Boolean Value
Changing Boolean Value
There are other properties that can only be set to true/false such as the examples below. These are called boolean values.
There are other properties that can only be set to true/false such as the examples below. These are called boolean values.
Changing Color
Changing Color
Changing the color of a part is slightly different that the example above, so this is how it looks:
Changing the color of a part is slightly different that the example above, so this is how it looks:
The names for the different colors can be found in the colors section by hovering your mouse over a color!
The names for the different colors can be found in the colors section by hovering your mouse over a color!
Touch Events
Touch Events
How to use touch events
How to use touch events
Functions
Functions
Changing other parts
Changing other parts
Changing Player Properties
Changing Player Properties
Parameters
Parameters
Part Interactions
Part Interactions
Scripting in a Model
Scripting in a Model
For Loops
For Loops
Models and Touch Events
Models and Touch Events
Disco Pad
Disco Pad
GUI Buttons
GUI Buttons
How to script GUI Buttons
How to script GUI Buttons
Keyboard Input
Keyboard Input
Click Detection
Click Detection
How to use keyboard inputs
How to use keyboard inputs