Skip to content
← Back to Community
Lua crash course part 1
Profile icon

Before we start

Lua is a lightweight scripting language that still has many uses today.

Roblox Studio uses it and even has special APIs for they're scripts.

It is also very suitable for a beginner's language.

This is the contents:

  • Part 1:
    • Comments
    • I/O
    • Data types
    • Variables
    • Tables
  • Part 2:
    • Basic operators
    • If statements
    • Loops
    • Functions
  • Part 3:
    • OOP in Lua
    • Exception handling
    • Sources used

Lua Crash Course part 1

In this tutorial, I will explain the basics of the Lua programming language.

I will try to be clear and concise with everything so that you can easily learn this.

More stuff:


What are comments?

Comments are part of a program that's not run.

A single line comment starts with -- and will make the rest of the line not run.


-- Single line comment

A long comment begins with --[[ and ends with ]].


--[[ Long comment. Can extend from many lines to part of on line. Throws error if not ended with: ]]

Yes, beware. The program will throw an error if the long comment is not ended.


The first program you will probably write for any given programming language is something that writes something similar to "hello world" in the console.

This is extremely simple in Lua. You use the print function

print("hello world!")

This is the same as Python and Swift.

We have done output to the console. Now let's do console input.

We accomplish that with

Unlike other programming languages, you cannot give a prompt string in the parenthesis

Basic Data types

Lua is dynamically typed.

Because of that, you can change the variable type anytime.

But the values have seprate types. Here are a few basic ones:

  • boolean - A boolean value (true/false)
  • number - Any regular number
  • string - A sequence of characters
  • nil - Nothing
  • table - A Lua table (explained later)

You can also see what data type a thing currently is with the type function:

type(<thing it will check the type of>)


type("this is a string type btw")


Variables are an essential part of Lua (and many other programming languages.)

Well what are they?

Think of them as values stored under a name.

They have the following syntax:

<name> = <value>

Since lua is dynamically typed, variable types can change at any time.

And also, as you guessed, you can use the type function with variables too.

Example for declaring variables:

variablesAreCool = true numExample = 791.32 stringExample = "this is an example of".." string concatenation" -- string concatenation combines things and makes them into a new string. fancyBoolean = 3 != 4 -- this is a condition. They are common in control flow (explained in next part.)

So now you have a bunch of variables and values. Good job!


What are tables?

Tables are basically your way to make arrays in Lua.

Unlike most other programming languages, tables have indices starting at 1.

If the stuff in there has a name, then it doesn't have an index.


tableExample = {4, "im number 2", false}

You can also have OOP based on tables, which will be explained in a future tutorial.

And so ends Part 1 of my Lua crash course. Tell me how to improve this and of typos and stuff.

Profile icon
Profile icon
Profile icon
Profile icon
Profile icon
Profile icon
Profile icon
Profile icon
Profile icon
Profile icon
Profile icon

How do you get the input from to the rest of the code?

Profile icon

@Catboi-Tipsy u can use this:
local test =

Profile icon

Please Don't cycle farm.

Profile icon

@AbhayBhat im not cycle farming

Profile icon

@nk1rwc, if you make a "crash course" or something, make it all in one tutorial. That will result in higher quality posts.

Of course, I cannot stop you but this is just my request/ recommendation: Make 1 Long post instead of many small ones.

Profile icon

@AbhayBhat three != many

i have tried and failed to make a series with many tutorials. this series is just three tutorials

Profile icon

@nk1rwc, oh well. Completely your choice..

Profile icon

@nk1rwc,I really liked your D tutorial though!

Profile icon

@AbhayBhat thx just busy working on the next part of the lua crash course

Profile icon

@AbhayBhat My stance is if there’s literally a 200 page book on the “basics” of it, break it up. If it can be covered in ~2 hours: don’t.

Profile icon

i really liked the tutorial but maybe make it longer next time.

Profile icon

@Nils2008 there are more parts to this series. i finished making the tutuorials a long time ago but you can read them

Profile icon