Luau vs Lua: What Changes for Script Developers
Luau vs Lua 5.1 for Roblox script developers. Type annotations, compound operators, string interpolation, continue, and what it means for obfuscation.
Roblox doesn't run plain Lua. It runs Luau, a language that started from Lua 5.1 and has grown a lot since. Most Lua code still works in Luau, but the reverse isn't true, and that matters for tools like obfuscators that were originally written for plain Lua.
Here are the differences that actually affect you when you write Roblox scripts.
Luau vs Lua at a glance
| Feature | Lua 5.1 | Luau | |---|---|---| | Type annotations | No | Yes, optional | | +=, -=, ..= | No | Yes | | continue | No | Yes | | String interpolation | No | Yes, with backticks | | if expressions | No | Yes | | Integer division // | No | Yes | | goto | No (5.2+) | No |
The syntax you'll use every day
Compound assignment. Instead of count = count + 1, write count += 1.
continue. Skip to the next loop iteration without nesting everything in an if:
for _, player in Players:GetPlayers() do
if player == LocalPlayer then continue end
print(player.Name)
end
String interpolation. Backtick strings let you write ` Hello {player.Name} instead of joining strings with ..`.
If expressions. local label = if alive then "Alive" else "Dead" replaces the old a and b or c trick, which breaks when b is false or nil.
Generalized iteration. for _, v in someTable do works without pairs or ipairs.
Types
Luau supports optional type annotations:
local function damage(target: Humanoid, amount: number): ()
target.Health -= amount
end
Types don't change how the script runs. They help your editor catch mistakes before you ship. For a script that runs in an executor, they're optional but useful on bigger projects.
Why this matters for obfuscation
Many older Lua obfuscators were written for Lua 5.1. Feed them a script with continue, += or backtick strings and they either fail to parse it or, worse, produce output that behaves differently. If you write modern Luau, check that your obfuscator understands it.
LuaProtect's obfuscator parses Luau directly, so you can keep writing modern syntax. You can test it on the free obfuscator. If you're curious what happens after parsing, our post on how VM obfuscation works walks through it.
Performance differences
Luau is fast: Roblox has put a lot of work into its compiler and interpreter. A few habits help:
- Use
table.create(n)when you know a table's size. - Cache services and frequently used functions in locals.
- Prefer
task.wait()over the deprecatedwait().
Summary
Luau is Lua 5.1 plus a lot of quality-of-life syntax and optional types. Write modern Luau freely, but make sure every tool in your pipeline, especially your obfuscator, understands it.