Roblox Studio

Roblox Lua Basics

2 min read Updated

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?
Mostly. Luau is Roblox's gradually-typed superset of Lua 5.1 with a few extra features. Standard Lua tutorials work for the basics.
Where do I write scripts?
Insert a Script object into a Part (for server code) or a LocalScript into StarterPlayerScripts (for client-side code).
Why isn't my script working?
Open View → Output and read the error message. The most common beginner mistakes are typos in property names and forgetting to call :Connect() on an event.
How do I learn more advanced Lua?
Roblox's official Creator Hub has free deeper tutorials, and the Lua reference covers the language itself. Build small projects to practice.
Keep reading

Related guides