Scripting is the magic that makes Roblox games fun! Scripts make objects dynamic and interactive and even allow game events such as those in “Natural Disaster”! In this Roblox scripting tutorial, we will get you started on coding for Roblox, and show you how to use the scripting language Lua to make and improve your own Roblox games.

Get started with Roblox scripting

Today we will answer some basic questions about Roblox scripting and then dive right in to how to script in Roblox.

Is scripting allowed in Roblox?

Scripting is definitely allowed in Roblox and Roblox scripts can in fact do a wide variety of creative things.  Almost all games in Roblox use scripts to make them more dynamic and fun.  Roblox scripting is done in the Roblox Studio editor and uses a programming language called “Lua”.

Is Roblox scripting hard to learn?

Lua is one of the easier programming languages to learn. That said, if you’ve never done any programming before, you may find some of the concepts tricky at first.  Children under the age of 10 may not be prepared to program in Lua. But for everyone else, just hang in there and things will soon start falling into place and making sense for you. Join a fun Roblox coding camp to enjoy live instruction from an expert every step of the way! You can even start free:

Follow the Roblox scripting tutorial

1. What is a variable?

A variable is a name associated with a value. You can think of a variable as a box that values can be put in, whether they are string values, number values, or even Roblox game object values. Once a variable is created, it can be used again and again. You can access the value whenever you want and you can even change the value as needed.  

What is a variable in Roblox scripting

In Lua, a variable is created as follows:

Variable

For example:

To display number of enemies in the Output panel:

2. What can I name a variable?

Variables can be named almost anything; the only real rules are that they must start with a letter and include only letters and/or numbers and underscores (“_”).  However, rather than using meaningless names like xyz29342, it is better to use meaningful names like WeaponToUse. This, quite simply, makes the variable easier to remember and understand.

3. Can variables have other variables inside of them?

Just like a box can have smaller boxes inside of it, a variable “box” can have more variable boxes inside of it. In fact, all game objects in Roblox are boxes with more boxes inside of them. The inside boxes have all of the descriptive properties about the game object, such as Position, Size, and Color.  

Roblox scripting variable

To access these inner boxes, we put a period (“.”) in between the name of the big box and the small box.

Using a period to script

4. Roblox variables

Roblox automatically creates some variables for you. The most important one is called “game”. Game is a box of boxes of boxes that lets you get access to everything running in a Roblox experience. For example, if you want access to a part called “MyPart” in the Workspace, you can just type:

MyPart

5. Roblox Object Properties

Roblox also automatically has a set of useful variables inside of all game objects. These include things like Position, Size, Color, Anchored, CanCollide, etc. Anything that you see in the Properties panel is an object variable, also known as a Property.

Properties panel in Roblox

So if you want to make MyPart invisible, just type:

If you want to anchor MyPart, just type:

6. Roblox Events and Functions

Roblox is always watching the game for specific things to happen, such as when a player joins the game, when a character dies, or when two objects touch each other.  These things are called Events, and a game developer can ask Roblox to tell them when these things happen so that the game can do something in response.  

For example, if the game needs to set the players scores to zero when they join the game, the programmer can code this:

If the game needs to kill the player if it touches a Lava Brick, the programmer can code this:

Tutorials to learn scripting for Lua

Roblox is a popular platform, and there are many resources available online to help one learn how to develop for it. Here are three online tutorials that are great for beginner through advanced learners!

1. TheDevKing YouTube tutorials

TheDevKing has two great playlists for learning Roblox scripting… one for Beginners, and one for Advanced learners.  Together, this set of videos can take a learner all the way from knowing nothing to knowing how to make advanced games.  TheDevKing’s conversational and friendly tone makes this a very welcoming channel that any learner can feel comfortable with.

Best for: Beginners to advanced

2. B Ricey YouTube tutorials

B Ricey’s YouTube channel carries a great set of video tutorials that start from the very basics and teaches Lua directly in the context of Roblox and Roblox Studio. This is a great option for beginners 10 years of age or older.

Best for: Beginners

3. Roblox Learn website tutorials

The Roblox Learn website is a great resource for intermediate level coders. The CODING section will teach you how to apply Lua to make Roblox games. It will also teach you how to use the Roblox Studio editor and all of its features. The Roblox Learn website is a great option for self-directed learning.

Best for: Intermediate

Roblox coding tutorial for beginners

Today we have learned some of the core concepts about Roblox scripting. Now you know how to begin teaching yourself scripting on Roblox. Of course, this is just the tip of the iceberg. Luckily, most games only need a small amount of the power that Roblox provides, so you can start making your own games even after just learning a few basic things. There is nothing better than learning from a teacher that knows exactly what they are doing and how to help you.  

If you are interested in learning how to make Roblox games, a great next step is to sign up for Create & Learn’s project-based Roblox Studio courses, where you will be making your own games in every single class with the help of a live expert instructor! There's even a free Roblox intro class to begin with so there's no risk in trying.

Written by Ken Patel, who started coding at age 10. Following his passion for video games, when he entered university he enrolled to study Computer Science. After graduation, he embarked on a career as a professional video game developer. Ken is excited to be sharing his passion, knowledge, and experience with the next generation of game makers through his role as a teacher here at Create & Learn.