Lua is the language of Roblox scripts. Print your first messages and learn how comments work.
Your first scriptTry itprint("text") shows a message in the Output. It is the first tool for seeing what a script does.
A game introExerciseScripts run from top to bottom. The order of the lines is the order things happen.
Notes for humansExercise-- starts a comment. Everything after it on that line is ignored.
The comment that broke the scriptDebugOne unreadable line stops the whole script. Lua comments are --, not //.
Quick checkQuizprint for messages, -- for comments, and the script runs top to bottom.
2. Variables
Coins, health, player names: games are full of values that change. Store them in variables, do math, and join text with ..
Store a valueTry itlocal name = value creates a variable. .. joins text and values.
Taking damageExercisex = x - 5 (or x -= 5) changes a variable using its own old value. Math uses + - * /.
Adding text with +Debug+ adds numbers. .. joins text. Mixing them up is the classic Lua mistake.
Is the player alive?ExerciseLua types: number, string, boolean, nil (and table, coming soon). type(x) names them.
Quick checkQuizlocal variables, math that updates them, .. for text, and the types number, string, boolean and nil.
3. Decisions with if
Can the player afford the sword? Is the boss defeated? if, elseif and else let your game decide.
Can I buy the sword?Exerciseif / then / else / end. Comparisons: ==, ~= (not equal), <, >, <=, >=.
Health colorsExerciseif / elseif / else: the first true branch runs, the rest are skipped.
The missing wordDebugif ... then ... end: both then and end are required.
Two keys for one doorExerciseand, or, not combine conditions.
Quick checkQuizif/then/elseif/else/end with comparisons and and/or/not.
4. Loops
Countdowns, waves of enemies, laps: loops repeat code so you don't have to.
Count the lapsExercisefor i = start, stop do ... end repeats, and i tells you which round it is.
CountdownExerciseThe third number of a for loop is the step. -1 counts down.
Spawn until fullExercisewhile condition do ... end repeats until the condition is false.
The loop that never stopsDebugA while loop needs something inside that eventually makes the condition false.
Quick checkQuizfor with a counter, a step for counting down, and while for "until something happens".
5. Tables and functions
An inventory is a table, a player is a table, and a heal is a function. The two building blocks of every Roblox game.
The inventoryExerciseTables as lists: {a, b}, table.insert, #list, and for i, v in ipairs(list).
A player as a tableExerciseTables with names: { Key = value }, read and change with table.Key.
A heal functionExerciselocal function name(params) ... return value end packs code into a reusable piece.
name or Name?DebugName and name are different keys. A missing key gives nil.
Quick checkQuizTables hold lists and named values. Functions are reusable code that can return results.
6. Build the world
Parts are the blocks every Roblox world is made of. Create them, size them, color them and place them, from code.
Your first partTry itInstance.new("Part"), then set Name, Size, Position, Color, Anchored, and Parent = workspace.
A staircaseExerciseUse the loop counter in Position to place parts in a pattern.
A glass windowExerciseTransparency, Shape and Material change how a part looks.
The invisible platformDebugNothing appears until its Parent is set (usually to workspace). Set Parent last.
Quick checkQuizInstance.new, Vector3, Color3, Transparency, Shape, and Parent = workspace.
7. Players and events
Games react: a player joins, a coin is touched, someone steps on lava. Events and :Connect make it happen.
Welcome, playerExerciseevent:Connect(function(args) ... end) runs your function every time the event fires.
A leaderboardExerciseA Folder named leaderstats under the player, with IntValues inside, makes a leaderboard.
Collect the coinExerciseTouched + GetPlayerFromCharacter + leaderstats: the core of collecting things in Roblox.
The lava blockExerciseFindFirstChild safely looks for a child: it returns nil instead of crashing when it is not there.
The spikes that crashedDebughit is a body part; the Humanoid is in hit.Parent. FindFirstChild avoids crashes.
Quick checkQuizPlayerAdded, Touched, :Connect, leaderstats and Humanoid: real Roblox game scripting.
8. Lua exam
Ten questions about Lua and Roblox scripting. Pass with 8 right answers.
The Lua examExamVariables, decisions, loops, tables, functions, parts and events: you can script real Roblox games.
9. Final project
Script a mini obby of your own: a course, collectibles, danger and a leaderboard. Then send it for review.
Your own obbyFinal projectPlayers, leaderstats, parts and events together: that is a real Roblox game.
How the course works
You learn by doing: each lesson explains one idea, then you write real code in the editor and see the result right away. The first lesson is free to try without an account; sign up to save your progress and continue.
Try it
Change working code and see the result immediately.
Exercise
Complete a task. A checklist confirms each requirement as you type.
Debug
Fix code that is broken on purpose, and learn why it failed.