Roblox uses Luau, a variant of Lua. The basics are the same: variables, conditionals, loops, functions, and events. You can write a useful script with just these five concepts.
Variables
A variable stores a value. Use local to keep variables scoped to the script.
- local message = 'Hello, world'
- local score = 0
- local isAlive = true
Conditionals
Use if to make decisions.
- if score > 10 then print('You win!') end
- if isAlive then print('Still here') else print('Dead') end
Loops
Loops repeat code.
- for i = 1, 5 do print(i) end
- while score < 10 do score = score + 1 end
Functions
Functions group code you want to run more than once.
- local function greet(name) print('Hello, ' .. name) end
- greet('Alex')
Events
Roblox is event-driven. Connect a function to an event with :Connect().
- local part = script.Parent
- part.Touched:Connect(function(hit) print(hit.Name .. ' touched me') end)
A complete example
Insert a Script into a Part. Paste this to make the part change color and damage anything that touches it.
- local part = script.Parent
- part.Touched:Connect(function(hit)
- local h = hit.Parent:FindFirstChild('Humanoid')
- if h then
- part.Color = Color3.fromRGB(255, 0, 0)
- h:TakeDamage(10)
- end
- end)
Frequently asked questions
Is Luau the same as Lua?
Where do I write scripts?
Why isn't my script working?
How do I learn more advanced Lua?
Related guides
What Is Roblox Studio?
Roblox Studio is the free creation tool used to build every game on Roblox. Here's what it is, who uses it, and what you can make with it.
Read guideRoblox Studio: A Beginner's Guide
Everything a beginner needs to start with Roblox Studio — the interface, parts, properties, the Toolbox, testing, and your first script.
Read guideHow to Create a Roblox Game
Build your first Roblox game from scratch using Roblox Studio — install, pick a template, customize, and test in under an hour.
Read guideHow to Make an Obby in Roblox Studio
Build a complete Roblox obby (obstacle course) in Studio: jumps, kill bricks, checkpoints, and a finish. No prior scripting needed.
Read guide