Introduction
Most scripting tutorials start by introducing various concepts available in Lua and providing the functionality that those commands do - but it can still be difficult for beginners to take those commands and actually use them to start writing their own code.
This tutorial takes a different approach. Rather than introducing the functionality that Lua provides, I’m going to start off by talking about a very core aspect of programming - writing down processes in a series of steps.
Why Bother with Steps?
No matter the language, programs serve to provide one function: telling a computer what to do. This is the same case with scripting in Roblox; when you write a script, that script is designed to communicate to the Roblox engine what should happen in your game. But as the programmer, your job is not to learn how to think in code - instead, your job is to divide your problems into simple steps which can be eventually translated into code.
Take a simple example. In most obstacle courses, there’s a concept of lava - when a player touches the lava, they’ll die. The objective is to jump past all these lava parts to move on in the course.
But how does lava actually work? If you jump into Studio and look at the code, it can look mystifying - there’s a lot of weird words, a mix of brackets, etc., and to somebody not well experienced with Lua, this can be very difficult to make sense of.
But that’s where writing the steps out can come into play. The typical process taken by lava is:
- Something touches a part
- Is the thing making contact a player?
If it is:
3. Kill that player.
And while this may not help to make sense of the actual code that you’d see in a script, it’s something that you should be able to make some sense of for yourself: it’s written out in English, and it seems to follow a simple process.
That’s all a program is doing - the only difference is that Lua is designed to make sense of those steps for the computer, while writing it in English is designed to make sense of it for you as a person.
So how do I come up with the steps, then?
For someone just starting out at the craft, identifying the steps for a process can be difficult - but it’s something that you can become an expert at with enough practice.
One way of doing it is to imagine that you’re talking to a younger sibling and trying to explain the concept to them, provided that they’d have basic knowledge, but would have had no prior experience with it.
Let’s start with an idea of making a bowl of cereal (the cereal goes first, of course!). What would the steps look like for something like that?
First, we’d want to grab the box of cereal, a bowl, and some milk. We’d pour the cereal into the bowl, then proceed to fill it with milk. Finally, we drop a spoon into the bowl, put back the cereal box and milk, and we’re done!
Written as a list, this would be along the lines of:
- Grab the bowl, the cereal box, and the milk
- Pour the cereal into the bowl
- Pour the milk into the bowl
- Put a spoon into the bowl
- Put the cereal box and the milk back
- Eat the cereal!
Now let’s look at something more along the lines of scripting for Roblox. Say you have a teleporter - when somebody steps in one side, they end up at the other. What would the steps look like for something like that?
- An object touches one end of the teleporter
- The teleporter checks that it was touched by a player
If the teleporter was touched by a player:
3. The script determines the position of the other end of the teleporter
4. The script places the player at the position of the other teleporter
You can also come up with examples of this from your own games, from your own homes, etc. This is one of the most key skills you’ll need as a programmer, so it’s definitely something that you’ll want to get enough practice with.
Moving Beyond / Conclusion
This tutorial has introduced a three step framework for programming:
- Determine the problem you’re trying to solve
- Simplify the problem into a series of steps
- Determine the code needed to drive that process
It does not, however, provide a deep dive into the commands that are offered by Roblox and Lua. For that, there are many other tutorials, with some being linked in the Additional Resources section below. This tutorial was rather designed as a way of bridging the gap between what those tutorials teach and the problems that you may face: how can you think in terms of steps and guide those steps into statements of code.
Thank you for reading, and please feel free to message me or respond with any questions - this will allow me to improve the tutorial and offer a better guide to everyone looking to start with programming. I also suggest diving into many of the other tutorials that I will link below in order to dive deeper into the step of writing code.
Additional Resources
AlvinBlox has an excellent series of scripting tutorials for beginners on YouTube: https://www.youtube.com/watch?v=BfLUt3mfJiY
As well as the wiki, which provides many excellent written articles: Documentation - Roblox Creator Hub
The wiki also provides an API listing for everything which you may have to interact with, which can be found using the search function on the Roblox wiki: Documentation - Roblox Creator Hub
Finally, looking into flowcharts may help you to grasp the step-by-step process of programming - while also providing a useful tool for looking at this kind of thing visually. There’s a lot of tutorials available if you search it up on Google, and @Thundermaker300 below provides a nice intro into it - so definitely look into that if you’re interested!