Tutorial page
This article is an easy tutorial.

Introduction

Welcome! If you're new to scripting, you've come to the right place. This is a complete beginner tutorial series that will teach you the fundamentals of Roblox scripting. I know you want to start clicking on things and learning things, I want to take a minute to explain what you will and won't learn.

Author's Notes

Imagine there's a little dot, and that's you. If you've done any research, you'll know scripting with Roblox isn't just a one dimensional field, there's games, cutscenes, and it will seem overwhelming. Well, the good news is you don't need to know everything. 20% of the features in scripting are used 80% of the time. I'm teaching you those core concepts to feel confident learning, and I'm separating it by level for free. It's really just chapters. Following start to finish will teach you how to make it. The below is part one, and to keep it interesting you can learn how to set a player head on fire.

Inserting a Part

Open Roblox Studio for the first time and create a Baseplate in the "New" tab, and you'll see this big area. If you don't see anything but that baseplate, don't worry, you don't have to put anything in there for now.

50% of your time is spent in the viewport. If you're modeling or moving something around, you'll do it here. Let's talk about that more.

If you go down into your Explorer panel on the side, you'll see a "Workspace" tab. This tab holds all Parts in the game. If you do not see an Explorer Window, go to the View Tab, then turn on the Explorer window. You'll also need the Properties window.

Go back to the Home window and click Part (the button with the cube on it.) A gray brick should appear on the baseplate. To move it around, you can use the "Select" tool or the "Move" tool. You can move around the part along one dimension by pulling on one of the arrows using the Move tool.

You can also resize the part using the "Scale" Tool and rotate it using the "Rotate" tool.

Now you need to know how to insert other parts into your game, like fire. Go to the Explorer window and then find the Workspace tab. Open the arrow beside it and find the Part. Then, hover over the Part tab, click the plus sign, and insert a "Fire" object. If you cannot find it, you can use the search bar.

Congratulations, you just created your first fire part! But what about scripting? We'll get to that right now...

Properties

In the Newbie's Scripting Guide, you learned a had a very broad understanding of a property, which we'll explain in more detail now. A property is a value attributed to a part that makes it look like what it is. For example, the Transparency, Size, and Position are all properties of a part. Property values are the numbers or words that are used to set a property. How do you do that? You can go to the Properties window, find the property, then type in the value.

The main properties a beginner should know are:

  • Transparency: the amount of light that passes through the object. This is a number value, where 0 means completely opaque and 1 is completely invisible.
  • BrickColor: the color of the brick.
  • Color3: an alternative to BrickColor, only it takes 3 number values.
  • Name: the name that is attributed to the brick.
  • CanCollide: whether or not other objects will pass through the object; if the checkbox is flicked off, objects could pass through it uninterrupted.
  • Anchored: whether or not the object is subject to change position. If the checkbox is turned on, the object will not be affected by gravity.

But how do you set a property using a script? Well...

Accessing a Property

You will have already have a basic idea on how to make a path, but now we will give a more concrete explanation.

First we need to access the part. Start by typing "game".

game

The word game should turn blue (or red if you had dark mode enabled.) Now, access the Workspace, by typing a period, then "Workspace".

game.Workspace

Then, access the Part. You'll notice that the part tab has a little indent compared to the Workspace tab. We say that the Part is the Workspace's "child," and that the Workspace is the Part's "parent." You can see that it resembles a hierarchy, doesn't it? So, when we access a part, we have to type all its ancestors, each separated by periods. So for this Part, we will type in:

game.Workspace.Part

Of course, if you had renamed the Part, you'd need to replace "Part" with the name you gave it. Also, make sure that no two parts are given the same name: otherwise the script won't know which part to access.

Now we set the property. We say that the property is a child of the part. So...

game.Workspace.Part.Transparency

To set the value, type an equal sign, followed by the value. So the completed code would be...

game.Workspace.Part.Transparency = 1

Spaces around the equal sign is optional, but it makes the script a whole heck of a lot neater. So, when you playtest the game, you'll see that the part suddenly vanishes. In reality, it had just been made invisible by the script.

But what if the script is the child of the part you want to access? This code would theoretically still work, but it makes more sense to use a shortcut. We can instead do this:

script.Parent.Transparency = 1

There are a few new terms here. When you say "script," the game will assume it means the script you're on. When you say Parent, instead of looking for the script's child, it'll access its parent. If you had made a mistake, chances are the game will have noticed it. Go to the View Tab, then click on "Output." A window will appear, and if the game found an error, it would print an error message nice and bold in red. Clicking on the red message will take you to the source of the problem.

Note: If you need to set a text value, place the value in quotations. Also, Color3 and BrickColor values are done differently, and I'll need to cover that later.

Print

Printing is an essential part of debugging your game. If you haven't already, open the Output window with the instructions given above. Then, in any script, type the following:

print("Hello!")

When you open your game, you will see that "Hello!" was posted in the Output window. It has no function in a live server, but is essential should you come across a bug you can't solve.

Variables

Now we discuss variables. Variables are, in short, placeholders for data. It would store information such as numbers and text. There are 5 main types of variable values:

Instances

All these are instances.

An instance is an object in the Explorer. This refers to parts, light objects, and more. An example of this is the Parent property of a part.

To set an instance property, make a path, like explained above:

script.Parent = game.Workspace.Car

Integer Values

An int value, otherwise known as an integer, is basically any number that is not a decimal. An example of this is the Brightness setting of a light object.

To set an int value, you can simply enter the number. Note that it should turn aqua.

game.Workspace.PointLight.Brightness = 12

Float

A double-precision floating point format, known in the Developer Hub as a float, is any number that allows for decimals. Just like int values, you can simply enter the value.

script.Parent.Transparency = 0.02

Boolean

A boolean, otherwise known as a bool value, is a value that is either true or false. In the Properties window, the properties with a checkbox is a boolean.

Checkboxes imply booleans.

To set a boolean, enter either true or false.

script.Parent.Anchored = false

Strings

A string is any text that uses letters or symbols. To enter one, you must wrap it in quotation marks.

script.Parent.Name = "Cheese"

Here, the word "Cheese" is wrapped in quotations.

Of course, there are other data types, like CFrame and Enum, but we'll get to that later.

Declaring Variables

When we introduce a variable to the script, we declare it. To declare a variable, simply type:

local VariableName = 1

Adding 'local' to declare a variable is entirely optional, but it is highly recommended, and you will see why in the Intermediate Tutorial.

So if you were to print the variable name, it would post its value in the Output window.

But what's the difference between these two lines?

print(VariableName)
print("VariableName")

When you put data in strings, you need to place them in quotation marks. So, in the second line, you are telling the script to print the string, so you would see "VariableName" in the output window. In the first line, you are telling the script to print the variable, so it would print the value, 1. However, make sure the variable name is spelled correctly, otherwise it'll get an error.

Note that variables cannot be accessed from other scripts.

BrickColor and Color3

Earlier, I left you hanging on how to set Color values. Well, BrickColor is fairly simple:

script.Parent.BrickColor = BrickColor.new("Really red")

Color3, however, is done differently. There are 3 main ways to do it.

You can do it using RGB values. If you are unclear of what this means, it is a way to add red, green, and blue together using number values. It is done like this:

script.Parent.Color = Color3.new(0,1,0)

In this case, (0,0,0) is black and (1,1,1) is white. If all three values are the same, the color will always be some shade of grey. Of course, most of the time you will need to use decimals. However, you can also do it like this:

script.Parent.Color = Color3.fromRGB(230,230,230)

This method also uses RGB values, only the values are from 0 to 255, where 0,0,0 is black and 255,255,255 is white.

That brings us to the third method:

script.Parent.Color = Color3.fromHSV(0,1,0)

In this case, rather than using RGB, it uses HSV. This stands for hue, saturation, and value (lightness). If you wish for an explanation, see here. All numbers should be between 0 and 1.

Vector3

There's another exception to setting properties. Position and Size both use three values: X, Y, and Z. To set these, we use Vector3.

script.Parent.Position = Vector3.new(1,2,3)

Here, I am setting the X coordinate to 1, the Y coordinate to 2, and the Z coordinate to 3.

Comments

Now, what if we don't want to forget what each line does? It'd be such a hassle to have to read each line over and over again. So, placing 2 dashes, followed by the text, will make the script ignore the text.

script.Parent.Transparency = 1 --Makes brick invisible.

In this case, the script will perform the code, before ignoring the text you wrote after.

Functions

Which brings us to the final topic of the beginner tutorial: functions! A function is a piece of code that can be used over and over again. Like variables, we declare them. We do it like this:

function Oof()
    print("Oof")
end

To make it actually work, though, we will need to CALL the function. We do it just like this:

Oof()

Note: Oof is the function name.

Remember that all functions need to have a corresponding end tag, and code inside functions should be indented.

And that's all you need to know for now! Go over to the intermediate tutorial to continue. Good day.

Community content is available under CC-BY-SA unless otherwise noted.