Lua Coding for Kids

iD Tech in action

Just like people speak different languages, so do programs! Meet Lua, the coding language spoken by popular gaming platform Roblox, and thus the perfect introduction to coding for kids and specifically young gamers.

As a language, Lua is great for kids and teens who want to pick up a language quickly, are eager to make the popular game their own, or are just interested in seeing how the worlds of gaming and coding collide. 

By learning Lua, kids will not only be able to build their coding repertoire (or even try it for the first time), they’ll delve deeper into game development and game design. 

Budding entrepreneurs might even get to make their own Robux along the way!

What is Lua coding?

Originating from Brazilian programmers, Lua (fun fact: this translates to "moon" in Portuguese!) is a straightforward programming language that’s designed to enhance applications. Translation: Lua is a useful coding language for customizing apps and games.

Currently, Lua is implemented by companies like Adobe and Firefox, and it’s the language that runs awesome games like those on Roblox and World of Warcraft. Impressive, right? But don’t be intimidated: like all the best coding languages for kids, Lua’s designed to be simple to learn with plenty of room to grow!

How to start learning Lua coding

With Roblox coding, kids can create anything they can imagine. Explosions? Check! New characters? Yep. Swords of awesome power? Absolutely! So, let’s take a look at a few beginner-level Lua coding projects. 

(First things first, kids should download Roblox Studio, a free creative engine as limitless as your child’s imagination. Then, they can give one of these introductory Lua challenges a try.) 

Making a New Script in Lua

To learn Roblox scripting - or to learn to code in general - it's crucial to form an understanding of and define the many terms you'll see over and over again. 

Lua scripts contain pieces of code used inside Roblox, and can be as simple as a single line of code, or as long as a chapter book. When you create your first script, it will open the Script Editor automatically. 

To create your first script, in the explorer:

  1. Hover over ServerScriptService to see the + symbol.
  2. Click the + symbol.
  3. Select Script from the drop-down.
  4. Right-click > Rename the script.
  5. Name the script "PracticeScript."

As a game designer, kids can expect to be creating a lot of scripts. So, it's really important for them to remember to name each script so they don’t mix them up.

To run the code:

  • Press the Play button — the same one used to run the game.

Wait, what happened?

  • Check the bottom of the screen; you should see the output window. 
  • Look closely and there will be a single line that says “Hello World.”
  • If you don't see the output screen with the Hello World! text, click to the View tab at the top and select Output.

Want a different message? The "Hello World" message can be easily turned into anything young coders can think of. Talk about their favorite Roblox game, Dragons, Dragons in Roblox, Roblox in Dragons, anything!

Try creating a different message. In the Script Editor:

  1. Change the text that's between the quotation marks.
  2. Run the code.

If a mistake is made as one is coding, error messages will show up as red lines in the Script Editor and in the output window. To check code:

  1. Click in the Script Editor.
  2. Delete a quotation mark from the print statement.
  3. Hover over the red line to see the error message.
  4. The error message says “Expected identifier when parsing expression, got malformed string.” That usually means it’s missing a quotation mark.
  5. Put the quotation mark back where it was deleted from to resolve the error.

Ready to keep going? Here are a few simple Lua programming projects that will get kids closer to being a developer in no time!

Changing Brick Color with Code

When designing, kids will learn how to edit properties, such as the size and scale of certain parts while inside the editor. But they can also edit properties inside a script as well! 

For example, they can use code to change a game's BrickColor property of a Part. To do so, they’ll need to do things like give the program directions on how to get to the Part of which they want to change the color. Then, they’ll have to learn how to replace a string variable in the BrickColor property, and more. 

Another example of how coding can take things to the next level is the fact that a brick doesn’t have to just remain one solid color of red or blue! With the help of variables as mentioned above, and loops, Parts can more resemble a unicorn if anything, with colors that continually change forever. 

To accomplish, kids are going to use code to change the BrickColor property of a Part when the game starts. This can be an existing Part in a game, or they can create a Part to practice with.

To set up:

Select an existing Part or create a new one.

  1. Rename the Part “PracticePart.”
  2. Add a new script to the PracticePart.
  3. Rename the script “ChangeBrickColor.”

Creating Trap Parts

Trap Parts harm or destroy anything that comes in contact with them, and thus should be avoided! Traps can be used to create new challenges, and can be implemented with the OnTouch function. 

Again, this triggers whenever anything touches the Part, but can be taken a step further, and coded to, say, check that whatever touched the Part is human.

  1. Create a new Part and name it “Trap.”
  2. Insert a new script into the Part and name it “TrapScript.”
  3. Create a variable that stores access to the Trap Part: local part = game.Workspace.Trap 

The goal is for the Trap to be triggered when a player touches the Trap Part, and Roblox has a function for just that called the onTouch function. This function triggers whenever anything touches the Part. Young creators can then test to see if the thing touching it is a human; if it is, then they'll destroy them!

  1. On a new line, write: local function onTouch(otherPart) 
  2. Press Enter, and you’ll see two new lines and the word end .

All the function’s code will need to be between the line you just wrote and end .

To test if the thing that touched the Part is a human, the parent of the thing that touched the Trap must first be found. The name of the object that touched the Trap is otherPart .

  1. Write a variable: local character 
  2. Store the parent of otherPart in that variable: local character = otherPart.Parent 

Now that the parent of the thing that touched the Trap can be accessed, the next step is to check to see if the child is a humanoid. Roblox has a function called “FindFirstChildWhichIsA" which will be used to see if they’re a humanoid.

  1. Write another variable on a new line: local humanoid 
  2. Call that function on the parent of the thing that touched the Trap: local humanoid = character:FindFirstChildWhichIsA(“Humanoid”) 

If the thing that touched the Trap is a humanoid then the variable humanoid  will be true; if they’re not a humanoid, the variable will be false.

  1. Write an if statement: if humanoid then 
  2. Set their health to 0: humanoid.Health = 0 

The last thing that needs to be done is to tell the function to activate whenever something touches it. This line of code will go at the very bottom of the script; it needs to go after both ends.

Get stuck? Try one of these troubleshooting techniques:

-Include a print statement within the custom function. If the print statement doesn't run when something touches the Part, the problem comes before that line of code.

-The statement connecting a function to the Touched event should come after the custom function.

-Make sure "Touched" is capitalized.

-Make sure the Touched event is being connected to the custom local function and not to the parameter.

Discover New Worlds with Lua and Roblox

Even if your child isn’t looking to immediately become a Roblox game developer or monetize their creations (right away at least!), it’s still worth exploring the interdisciplinary potential of this versatile coding language. At the very least, kids can engage more meaningfully with the game while love learning alongside it—and if you ask us, that’s always worth doing!

To help get your child started on this path, iD Tech offers virtual after school learning experiences, 1-on-1 Roblox tutoring lessons, and summer camps that will help transform your child’s love of gaming into valuable skills. 

A photo of Virginia

Virginia started with iD Tech at the University of Denver in 2015 and has loved every minute since then! A former teacher by trade, she has a master's in education and loves working to embolden the next generation through STEM. Outside the office, you can usually find her reading a good book, struggling on a yoga mat, or exploring the Rocky Mountains. 

Featured Posts



About iD Tech

iD Tech is the #1 tech camp on the planet, and world leader in youth STEM education, with programs held online and at 75+ global locations offering 50+ innovative tech courses: 

Coding camps
Video game camps
Robotics classes & camps
Creative arts classes & camps
All STEM camps

We've bet our reputation on recruiting the top instructors in the country. Our small classes ensure customized learning, leading to "a-ha moments" and awesome outcomes. Programs include:

On-Campus Programs

Online Tutoring

All Coding Courses