Luau Basics 1: Variables, Numbers, and Words
The short answer: A variable is a name that holds a value — like a labeled box. In Luau you make one with the word local, and the value inside can be a number, a string (text), a boolean (true or false), or nil (nothing there yet). Every example on this page was test-run before the page was written, and the output shown is the output it really produced. Paste any example into a Script in Roblox Studio and you will see the same thing in the Output window.
Variables: labeled boxes
Roblox's own language guide puts it in one line: a variable is a name that holds a value. You create one by putting the variable on the left of an = sign and the value on the right.
Almost every variable you write should start with local. A local variable belongs to your script, and Luau actually reads locals faster than globals — Roblox's guide says locals are almost always the better choice. Two naming habits from the same guide: names are case-sensitive (Coins and coins are different boxes), and it is best to spell words out fully and use camelCase for local variables — playerCoins, not pc.
The four beginner types
local playerName = "Alex"
local coins = 25
local hasKey = true
local mystery
print(playerName)
print(coins)
print(hasKey)
print(mystery)
print(type(playerName))
print(type(coins))
print(type(hasKey))
print(type(mystery))What you should see:
"Alex"is a string — text, always wrapped in quotes.25is a number. Luau has one number type for everything: whole numbers and decimals are both just "number."trueis a boolean — a value that is only evertrueorfalse.mysterywas never given a value, so it holds nil — Luau's word for "nothing there." If you create a variable and do not put a value in it, the value is nil.type()is a built-in checker that tells you what kind of value something is. Notice the last line: the type of nil is "nil."
Doing math
local coinJar = 10
coinJar = coinJar + 5
print(coinJar)
coinJar += 10
print(coinJar)
print(7 * 3)
print(7 / 2)
print(10 % 3)
print(2 ^ 10)What you should see:
+,-,*, and/are add, subtract, multiply, and divide. Division gives decimals: 7 / 2 is 3.5.coinJar = coinJar + 5means "take what's in the box, add 5, put the result back in the box."+=is Luau's shortcut for exactly that:coinJar += 10adds 10 to whatever is already there. (Plain Lua does not have this — it is one of Luau's own additions.)%gives the remainder after dividing: 10 % 3 is 1, because 3 goes into 10 three times with 1 left over.^is a power: 2 ^ 10 means 2 multiplied by itself 10 times — 1024.
Putting words together
Two dots, .., glue strings together. It is called concatenation. The glue adds no space by itself — if you want a space, it has to be in one of the strings.
local firstWord = "Hello"
local secondWord = "world!"
print(firstWord .. " " .. secondWord)
local visitorName = "Alex"
print(`Welcome back, {visitorName}!`)
print("Coins: " .. 25)What you should see:
- Line 3 glues three pieces:
"Hello", a string that is just a space, and"world!". - The middle example uses Luau's string interpolation: a string written with backticks ( ` ) instead of quotes can hold
{ }slots, and whatever is inside the braces gets worked out and dropped into the text. It is the tidy way to build a message out of variables. - The last line shows that
..can glue a number onto the end of a string — Luau turns the number into text for you.
Comments: notes Luau ignores
Anything after two dashes, --, is a comment — a note for humans that Luau skips completely. A long comment that covers many lines starts with --[[ and ends with ]]. Good comments explain why, so future-you can follow the code.
-- Luau skips anything after two dashes.
local speed = 16 -- This note sits at the end of a line.
--[[
This is a long comment.
It can cover many lines.
]]
print(speed)What you should see: just 16. The comments change nothing — they are only there for the reader.
Try it in Studio: open the script from page 2 of this series, delete its contents, and paste any example from this page in its place. Run the game and compare your Output window with the "What you should see" box. Matching output means your code ran exactly as written.
This page is part of the Roblox Luau series:
1. Installing Roblox Studio ·
2. Your First Script ·
3. Luau Basics 1: Variables, Numbers, and Words ·
4. Luau Basics 2: Choices, Loops, and Functions ·
5. Making Things Happen: Events ·
6. Saving a Player's Progress ·
7. The Player Talks to the Server ·
8. Build a Whole Mini-Game ·
9. Stay Safe and Keep Your Game Yours
Sources (official only; read in full November 7, 2026):
- Roblox Creator Documentation, Variables (create.roblox.com/docs) — a variable is a name that holds a value; assign with =; no value means nil; local scope is almost always better and faster; names are case-sensitive; spell words out and use camelCase for local variables.
- Roblox Creator Documentation, Numbers — the number type is a double-precision number; Luau does not separate whole numbers from decimals; type() and typeof() report "number" and "string."
- Roblox Creator Documentation, Strings — declare strings with quotes; combine them with .. (concatenation adds no space); string interpolation with backticks and { } slots.
- Luau language site, Luau syntax by example (luau.org) — Luau builds on the baseline syntax of Lua 5.1 and adds its own features, including compound assignments such as +=.
- Roblox Creator Documentation, Scripting introduction — comments with -- and --[[ ]].
Every code example on this page was run on a Luau interpreter before this page was written, and the outputs shown are the outputs the runs produced. Checked November 7, 2026.