Games

Lua Pro: Roblox for advanced

After the beginner course: smart tables, classes, cloning, debounce, timers and tweens, server and client, and saving player data.

10 chapters · 47 lessons · free

Try a free lesson Create your free account

What you will learn

1. Tables like a pro

Dictionaries, pairs, sorting and tables inside tables: how real games keep shops, inventories and player data.

  • A shop with prices Exercise A dictionary keeps values by name. pairs goes over every key and value (in no fixed order).
  • The player ate the apple Exercise table.find gives a position, table.remove takes out what is there, and table.concat turns a list into text.
  • Top 3 players Exercise table.sort(list, function(a, b) ... end) sorts in any order you want: return true when a comes first.
  • Everything about a player Exercise Tables inside tables: reach in with dots (data.stats.level) and with [ ] for lists (data.inventory[1]).
  • The empty shop Debug ipairs is for lists (positions 1, 2, 3...). pairs is for dictionaries (and works on anything).
  • Quick check Quiz Lists use positions, dictionaries use keys, and table.insert/find/remove/sort/concat do the rest.

2. Functions like a pro

Return several values, give defaults, pass functions around, make closures and format text: the tools behind every clean script.

  • A round timer Exercise return a, b gives back two values, and local x, y = f() catches both.
  • The heal that crashed Debug A missing argument is nil. value = value or default gives it a default.
  • A function as a value Exercise Functions are values: they can be passed to other functions and called there (a callback).
  • A counter that remembers Exercise A closure: an inner function keeps the local variables it was made with.
  • A tidy status line Exercise string.format fills %s, %d and %.1f with values. Text methods like :upper() and :sub() change texts.
  • Quick check Quiz Multiple returns, defaults with or, callbacks, closures and string.format.

3. Objects and classes

Methods with self, the colon that matters, an Enemy class you can make a hundred times, and modules shared between scripts.

  • A sword that swings Exercise function obj:method() gets the table as self. Call it with obj:method().
  • Dot or colon? Debug Methods made with : must be called with :. A dot does not pass self.
  • An Enemy class Exercise A class: methods in one table, __index pointing to it, and new making objects with setmetatable.
  • A shop module Exercise A module is a table of functions that a ModuleScript returns, so many scripts can use it with require.
  • Quick check Quiz Methods and self, classes with setmetatable/__index, and modules with require.

4. Working with the world

Clone templates, loop over folders, give objects your own attributes, and find things safely.

  • A row of coins Exercise :Clone() copies an object (and everything inside it). Set the copy's Parent to put it in the world.
  • Turn on the lights Exercise :GetChildren() lists what is inside an object, and :IsA("BasePart") tells parts apart from everything else.
  • Coins with different values Exercise SetAttribute/GetAttribute store your own values on objects, so one script can handle many different objects.
  • The missing key Debug A dot fails when the child is missing. :FindFirstChild(name) gives nil instead, so you can check it.
  • Quick check Quiz Clone, GetChildren with IsA, attributes, and FindFirstChild for things that may be missing.

5. Events like a pro

Debounce, buttons you click, Press E prompts, deaths and respawns, and events that run only once.

  • Spikes with a debounce Exercise Touched fires many times. A debounce (if busy then return end ... task.wait ... busy = false) makes it count once.
  • The coin worth 30 Debug An invisible part is still in the game. :Destroy() removes it and its connections.
  • A button to click Exercise A ClickDetector makes a part clickable, and MouseClick gives you the player who clicked.
  • Press E to open Exercise A ProximityPrompt shows "Press E", and Triggered fires with the player who used it.
  • Count the deaths Exercise CharacterAdded fires for every new character, and Humanoid.Died fires when it dies.
  • A bonus only once Exercise :Once runs a handler only the first time. connection:Disconnect() stops a connection whenever you choose.
  • Quick check Quiz Debounce, Destroy vs Transparency, ClickDetector, ProximityPrompt, CharacterAdded and Died, Once and Disconnect.

6. Time and animation

Timers with task.wait, things that come back with task.delay, smooth movement with TweenService, and the loop that freezes a game.

  • Round starts in... Exercise task.wait(seconds) pauses the script while the game goes on. for i = 5, 1, -1 counts down.
  • A coin that comes back Exercise task.delay(seconds, fn) runs fn later without stopping the script, great for respawning things.
  • A rising platform Exercise TweenService:Create(part, TweenInfo.new(seconds), goals) makes a smooth change, and :Play() starts it.
  • When the gate is open Exercise tween.Completed fires when a tween finishes, so you can chain what comes next.
  • The game that froze Debug A while true do loop must have a task.wait inside, or it freezes the game.
  • Quick check Quiz task.wait, task.delay, TweenService with Play and Completed, and why every endless loop needs a wait.

7. Server and client

Where your code really runs, how the server and the players talk with RemoteEvents, and how to stop cheaters.

  • Server and client Try it A RemoteEvent carries messages: FireServer on the client, OnServerEvent(player, ...) on the server.
  • Buying, the server way Exercise The server checks every request itself: the price comes from the server's own table, never from the client.
  • The free sword Debug Never trust the client: prices, damage and rewards are decided on the server.
  • A message to everyone Exercise FireClient(player, ...) and FireAllClients(...) send from the server; the client listens with OnClientEvent.
  • Quick check Quiz Server and client, RemoteEvents both ways, and never trusting what the client sends.

8. Saving data

DataStores that remember every player: save when they leave, load when they come back, and stay safe when the servers fail.

  • Your first save Exercise GetDataStore(name) opens a store; SetAsync(key, value) saves and GetAsync(key) loads.
  • Save when they leave Exercise Load in PlayerAdded (GetAsync(key) or 0), save in PlayerRemoving, with a key made from the UserId.
  • When saving fails Exercise pcall(fn) catches errors: it gives ok (did it work?) and the result or the error message.
  • The lost coins Debug Save and load with the exact same key, and build it from the UserId, which never changes.
  • Quick check Quiz DataStores with GetAsync/SetAsync, keys from the UserId, PlayerRemoving, and pcall for when things fail.

9. Advanced exam

Ten questions about everything in this course. Pass with 8 right answers.

  • The advanced Roblox exam Exam Tables, functions, classes, the world, events, time, server and client, and saving data.

10. Final project

Build Coin Rush: cloned coins, prompts, timers and saved progress, in one game of your own. Then send it for review.

  • Coin Rush Final project Data, cloning, events, time, prompts and saving, all in one game: this is how real Roblox games are made.

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.

  • Quiz

    Check your understanding at the end of a chapter.

More in Games

  • Lua: Roblox for beginners

    Roblox-style Lua from zero: from your first print to coins, lava and a working obby. Then go on to Roblox for advanced.