Tutorial:Newbie's Guide to Scripting

The purpose of this guide
This guide is for those who have absolutely no understanding of what scripting is and aren't able to write a single line of code. This guide won't teach you how to make the awesome stuff that has probably drawn your attention to this subject, but this will teach you what scripting is so you are at least capable to study all those tutorials and scripts made by others.

Note that this guide is focused on teaching the reader the main principles of scripting in Roblox and a way to get started with it, not to confuse the reader with complicated terms and being precise or exact. However, the learning curve in this article is still quite high, so if you have trouble understanding some parts, slow down and reread the article a few times.

Just keep in mind the following few things:


 * Know the difference between active and passive learning. You can read through all the scripting tutorials, but you cannot truly master Roblox Lua until you practice coding yourself using Roblox Studio. It is very much like learning a spoken language; it's a skill that is acquired through consistent and rigorous practice and making mistakes, not something that you learn by simply reading.
 * Do not try to cram all the learning material in one go and expect to master the coding language. It will take days just to learn the basics and around 3-6 weeks to master depending on your dedication, though it may vary from person to person. Take it slowly and do not move onto the next chapter until you are absolutely certain that you are confident with the material.
 * Do not be discouraged by the mistakes you make. I guarantee you that the front-page developers have made many errors and bugs and have had to solve them in order to get to where they are.
 * Start small. If you are looking for ideas for a first project, I highly recommend you do a basic project (like an obby or tycoon), not a big project like most games on the front page. If you are still learning the basics, it is unlikely that you will be able to create the next Jailbreak.

Introduction
Scripting is what actually makes blocks in Roblox do things, and without it, your character's limbs wouldn't move when you are walking and a rifle would just be a bunch of parts being held by your character, if it doesn't just fall apart when equipped. In short: scripting is what makes Roblox come to life and make places fun. It is very understandable that people want to learn how to do it and make cool places. Contrary to popular belief, scripting isn't hard at all, it's just something totally new that you need to understand first. It's very simple to make scripting easy. Just read these passages.

Roblox Studio Basics
We use a program called "Roblox Studio." If you play any Roblox game, the application will automatically be added to your device. Open the application and create a new place.

At the center of the screen is known as the viewport. It shows the "space" of your game. As you can tell, the viewport consists of three dimensions. This is known in geometry as Euclidean space.

Look at the top of your screen. It should look like this, assuming dark mode is turned off. It may look different due to updates, but the image below shows what it would look like as of June 25, 2021.

g started
Let me explain the basics:

There are five tabs at the top: Home, Model, Test, View and Plugins. For the purpose of keeping this tutorial simple, we will focus on the Home and View tabs.


 * The Home tab contains the most basic functions needed, such as creating parts and changing its color.
 * The Model tab is reserved for functions needed for creating more complex models, like unions and negates. However, we will not focus too much on this tab.
 * The Test tab contains functions used to test your game to look for bugs.
 * The View tab allows you to open certain windows in the game.
 * The Plugins tab allows you to use Plugins, which are downloadable tools to help with building and scripting.

For this tutorial, we will focus on the Home tab.

You should have the following windows in your game. If not, go to the View Tab on the top, and open the following windows:


 * Explorer. This is a manager for all the objects inside your game.
 * Properties. This is a window that manages and lets you manipulate the properties of an object. I will explain them in the beginner series.

You can reorganize the Studio however you like, but I like to keep the Explorer tab on the right of the screen, and the Properties and Output on the left.

The Home Tab
Let's focus on the functions of the Home Tab.

Tools
There are four functions under the Tools section: Select, Move, Scale and Rotate.


 * Select is a tool used to select and move parts around the studio. To use this tool, simply click the part to select it and drag it to where you want to go.
 * Move is a more accurate tool used for moving parts, where you can move a part along a certain axis. Drag the arrows to move them.
 * Scale is used to resize parts; that is, making a part bigger or smaller. Drag on the balls to resize the part.
 * Rotate is used to rotate the part; that is, to turn a part in a circular direction around a certain point. You can drag along the circles to rotate the part.
 * Transform combines all four of the above tools so that you would not have to toggle between the tools individually. However, it is quite difficult to use, so I recommend using each tool individually.

The Terrain Editor is used to add terrain (dirt, snow, grass, etc.) to your world. It is far easier to add terrain using the Terrain Editor than to build the terrain out of blocks.

Insert
There are 3 functions under the Insert section: Toolbox, Part, and UI.


 * The Toolbox opens a window that allows you to access free models, which are basically models created by other players that you are free to insert into your game. However, avoid using this feature excessively, and watch out for malicious codes inside the models that can ruin your game. Part Shapes.png
 * The Part function adds a block into the game. This is more commonly known as a Part, but they are officially called Base Parts. If you click on the ▼, you will see that there are 4 shapes of a base part: Block, Sphere, Wedge and Cylinder. Clicking on any of these options will spawn a base part into the :
 * The Block shape is a rectangular prism, characterized by six rectangular faces. These are recommended for building walls and floors as they have six flat surfaces.
 * The Sphere shape is a ball, characterized by one. These are best for building round things like sports balls, tear drops or boulders.
 * The Wedge shape is a triangular prism. These are best for building ramps, roofs, and other sloped surfaces.
 * The Cylinder shape is, well, a cylinder! It contains a circular base, which proves helpful for building pipes, bars, and wires, as well as flat round things like puddles or fried eggs.
 * The UI function adds a GUI, but let's not get too far into it in this tutorial.

Edit
Under the Edit section, we will focus on Material and Color.

Material affects the texture of a base part, or the general look of a part's surface. By default, the material is Smooth Plastic, meaning that there are virtually no creases or marks on the part. To change the material, select the part in the viewport. Then, click on the ▼ under Material, and select any material in the dropdown menu. Color is self-explanatory; it affects the part's color. By default, the color is Medium stone grey. Clicking on the ▼ gives you this palette:

Click on any color to change the color.

Test
There are just two functions under Test: Play and Stop. Play will allow you to play the game you created as if you were in a live server. Stop will return you to the viewport.

(If you cannot figure out what each tool does, a detailed tutorial for Roblox Studio can be found here.) Within the tutorial after this one, we will learn to create a script that activates once the part it is in is touched.

Writing a script
To create a script, hover over any tab in the Explorer window. A plus sign should appear. Click it, and find "Script" in the popup that appears. Click it, and you should have a script ready to go, with "print("Hello world!")". We will explain what it does in the Beginner Tutorial. For now, remove it. Now, your Explorer should look like this:We refer to this as a hierarchy, which means that one object is ranked "higher" than another. This is indicated by the indents in the explorer window. In the above case, the Workspace is the highest, because it has the least indent.

Because the Part is directly below the Workspace in the hierarchy, we say it is the Workspace's child, and the Workspace is the Part's parent. To be clear,

In the above case, the top brick is the parent of the bottom brick, and the bottom part is the child of the top part.

A path in Roblox scripting is like directions the script uses to access the script. You would start with game, then work your way downwards in the hierarchy, separated by dots. So, if I were to access the Part in the above example, game.Workspace.Part Now, we did that, but now what? This script would access the part, but would do nothing to it. So, we set a property. game.Workspace.Script.Name = "Script" --Change the name to whatever you want.

This would rename the script.

Good!

To run your script, click the green 'Play' button at the top of your screen. If the script's name changed to whatever you entered it to be, then congratulations! Your script works!