Skip to main content
Lua is a lightweight, fast scripting language that powers game logic in Roblox and many other platforms. Whether you are brand new to programming or coming from another language, understanding Lua’s fundamentals will help you read, write, and request scripts with confidence. This guide walks you through the essential concepts you will encounter in almost every Lua script.

Variables and Data Types

In Lua, you declare variables with the local keyword. Lua is dynamically typed, so you do not need to specify a type — the value itself determines it.
Lua’s core data types are number, string, boolean, nil, table, and function. You will use all of them regularly.

Functions

Functions let you group reusable logic under a name. You can define them with local function (scoped) or as values assigned to a variable.

Tables

Tables are Lua’s only data structure — they act as both arrays and dictionaries (key-value maps). They are the backbone of almost every Roblox script.

Loops

Lua provides for, while, and repeat...until loops for iteration.

Conditionals

Use if, elseif, and else to branch your logic. Lua uses and, or, and not instead of &&, ||, and !.

String Concatenation and Length

Lua uses .. to join strings and # to get the length of a string or array-style table.
Common Lua gotchas to watch out for:
  • Arrays start at 1, not 0. myTable[1] is the first element.
  • nil is not the same as false. nil means “no value exists”; false is a boolean. Both are falsy in conditions, but they are different types.
  • There is no null keyword — use nil instead.
  • ~= means “not equal”, not != like in most other languages.
  • Global variables are dangerous. Always use local unless you have a specific reason not to — accidental globals cause hard-to-find bugs.
  • String concatenation with .. requires spaces around it to avoid ambiguity with decimal numbers.

Keep Learning

Roblox Scripting

Put your Lua knowledge to work inside Roblox Studio with scripts, RemoteEvents, and the full game API.

Debugging Tips

Learn how to read Lua error messages, isolate problems, and fix issues faster.