Roblox and Luau
Prerequisites: Lua versions, LuaJIT, and Luau
Roblox games are scripted in Luau, Roblox's Lua dialect, inside Roblox Studio. The language basics from this course carry over directly; what's new is the engine API.
Scripts and services
-- A Script in ServerScriptService
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats
end)
-- A Script inside a Part: give a coin when touched
local part = script.Parent
local debounce = {}
part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player and not debounce[player] then
debounce[player] = true
player.leaderstats.Coins.Value += 1
task.wait(1)
debounce[player] = nil
end
end)
- The game is a tree of Instances (
game,Workspace, parts, folders);script.Parentis the object the script is inside. - Events (
PlayerAdded,Touched) take callbacks via:Connect— closures, as in Level 2. task.waitpauses the script — coroutines under the hood.
Client and server
- Scripts run on the server; LocalScripts run on each player's device (input, camera, UI).
- They communicate through RemoteEvents and RemoteFunctions.
- Never trust the client: validate every request on the server — exploiters can fire remotes with any arguments.
- ModuleScripts are Luau modules loaded with
require, used to share code.
Luau features worth using
- Type annotations with
--!strictcatch bugs in Studio before you play. +=,continue, and string interpolation with backticks.- Luau is fast (with native code generation) and sandboxed —
os,io, andloadare restricted.
The Roblox Creator Documentation (create.roblox.com/docs) has the full engine API and tutorials.