Learn Scripting

How to script in Roblox Studio

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.

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. . .


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"


After "game" the next largest sections are found in the explorer menu

Explorer Menu


Workspace Section


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:


game.Workspace.Part


Starting with the biggest section and moving to smaller sections until you get to the object you want

Another Example


If I wanted to reference the part labeled "ThisOne" how would I do it?


Try it yourself then check your answer below!

Reveal Answer

game.Workspace.Model1.Model2.ThisOne

Adding a Script

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:

1. Find that part in the explorer menu

2. Click on it

3. Click the + sign next to the name

4. Type script in the search bar

5. Click on script

After you do that you will now have a new script that you can begin write you code on!

Varaibles

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

game.Workspace.Part


Then if i wanted to change one of its properties then I would write something like this


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.


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!

Changing Properties of Parts

Setting a New Value

Some part properties can be change by simply setting that property equal to a new number. For example:

Setting a New Vector

Other properties can be changed by giving the property a new set of numbers called a vector. Examples include:

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.

Changing Color

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!

Touch Events

How to use touch events

Functions

Changing other parts

Changing Player Properties

Parameters

Part Interactions

Scripting in a Model

For Loops

Models and Touch Events

Disco Pad

GUI Buttons

How to script GUI Buttons

Keyboard Input

Click Detection

How to use keyboard inputs