Codectionary / Developer documentation / Luau

Start with Luau values and functions, then use Roblox Studio to connect that code to players, Instances and events. Luau is the language; Roblox supplies the game engine APIs. Codectionary supports editing and highlighting, while these Roblox examples run in Studio.

File extension
.luau
Runs in
Luau host; Roblox engine examples require Roblox Studio

Luau, Lua and Roblox

Luau is a scripting language derived from Lua 5.1. It keeps many Lua ideas while adding features such as a gradual type system and compound assignments. Roblox uses Luau for experience code; its engine supplies objects, events and services. Those APIs are not built into the standalone Luau language.

Choose Roblox Studio if you want to build an experience. Choose the standalone Luau CLI if you want to practise language syntax without Studio or embed Luau in another application. The ordinary Lua interpreter is a different runtime and does not accept every Luau feature.

Start in Roblox Studio

Install Roblox Studio using Roblox Creator Hub’s setup instructions for Windows or macOS, sign in, and create a new Baseplate experience. In Explorer, add a Script under ServerScriptService. Open it in Studio’s Script Editor, replace the starter code with the first example, then press Play. Open the Output window to see print results and runtime errors. Script Analysis and editor highlights help find syntax and type warnings.

The first example prints 12 from a small typed function. : number annotates parameters and the return value for Luau’s checker; it does not validate untrusted values at runtime. Try changing the arguments and watch Output. The second example creates a Roblox Part and requires Studio because Instance, Vector3, Color3 and workspace come from the engine.

  1. Install and open Roblox Studio.
  2. Create a Baseplate and find ServerScriptService in Explorer.
  3. Insert a Script, paste the first example and press Play.
  4. Read Output for the printed result and Script Analysis for diagnostics.

Which script runs where?

A Script in ServerScriptService is a sensible first server example. Server code handles shared rules and authoritative changes. A LocalScript runs on a player’s client only when placed in a supported client context; it is suited to local interface or input behaviour. A ModuleScript defines reusable code and runs when another script requires it, in the context of that caller. Merely creating a ModuleScript does not execute it.

Client code is not a trusted authority for scores or purchases. When the client needs a server action, use Roblox’s networking APIs and validate the request on the server. Learn script placement before building multiplayer interactions.

Try standalone Luau without Roblox APIs

The open-source Luau project publishes luau and luau-analyze command-line tools. Download a recent binary archive from its official releases for your platform, extract it, and put the executable directory on PATH; the project also documents source builds and some community-maintained packages. Save a language-only snippet in hello.luau, run luau hello.luau, and use luau-analyze hello.luau to check types and lint warnings. With no filename, luau opens an interactive prompt.

The standalone CLI is sandboxed and does not supply Roblox’s game, workspace, Instance or service APIs. Use only language-level examples there. Roblox code belongs in Studio (or a host that deliberately implements equivalent APIs). Type analysis is a separate step; running a script is not a substitute for checking types.

Run and analyse a standalone file

luau hello.luau
luau-analyze hello.luau

Script Editor and optional VS Code workflow

Studio’s Script Editor is the simplest starting point: it understands the experience’s objects, highlights code, offers completion and shows type diagnostics. If you prefer VS Code, Roblox’s Script Sync can mirror selected scripts or folders to local Luau files. In Studio Explorer, right-click a folder, choose Sync to…, select a local directory, then open that directory in VS Code. Changes can sync back to Studio.

Script Sync has limits: it syncs supported script and folder instances, not a complete experience, and an external editor cannot control Studio’s debugger. Check sync conflicts carefully. The Roblox documentation recommends its companion Luau language-server setup for richer VS Code assistance; Studio is still needed to run and debug Roblox engine behaviour.

Luau in Codectionary’s Playground

Codectionary lets you select Luau and edit or highlight examples, but it does not execute Luau or compile and type-check your code there. Therefore it has no Luau run output to inspect. Run language-only files with the standalone luau command, and run Roblox examples in Studio, where Output shows print messages and errors. External modules and Roblox engine APIs are not provided by Codectionary’s editor.

A beginner-to-advanced Luau path

Begin with local values, tables, functions and simple output. Add annotations and --!strict when you can explain the untyped program. In Studio, learn Explorer, Script Editor, Output and the three script types. Then study events, Instances and client/server boundaries. Move to remote-event validation, persistence and performance only after you can trace where each script executes.

Build small projects and test each boundary. A standalone snippet can teach language syntax, but it cannot prove that a Roblox scene, service or multiplayer flow works.

  1. Write and run a language-only greeting.
  2. Run a server Script in Studio and inspect Output.
  3. Add type annotations and fix diagnostics.
  4. Learn client/server placement before networking and persistence.

Syntax

local message: string = "Hello, Luau"
print(message)

Breaking down the syntax

local
Creates a binding in the current scope.
: number
Describes a value to the static checker; it is not runtime input validation.
Instance.new
Creates a Roblox engine object, not a standalone Luau language value.

How it works

Write a small function first. Once its inputs and outputs make sense, connect it to a Roblox object or event. Keeping those steps separate makes it easier to identify whether a mistake belongs to the code, the scene setup or the network boundary.

Language

Learn values, tables and functions with small outputs you can predict.

Engine

Choose a script location and connect the code to Instances and events.

Multiplayer

Keep authority on the server and validate requests before changing shared state.

Examples

Run language-only Luau

Save as hello.luau and run luau hello.luau with the standalone Luau CLI. This example does not need Roblox Studio.

--!strict
local name: string = "Codectionary"
print("Hello, " .. name .. "!")
  1. The --!strict directive enables stricter static checks when the file is analysed. The : string annotation tells the checker what value name should hold.
  2. The .. operator joins three strings and print writes Hello, Codectionary! to the terminal. The annotation does not create a runtime conversion or validation.
  3. This code uses only Luau language features. It does not use game or workspace, so it can run in the standalone CLI.

Your first Script

Roblox Studio: insert a Script in ServerScriptService, paste this code and press Play. Output shows 12. Changing the second argument changes the result without changing the function.

-- Script in ServerScriptService
local function total(price: number, quantity: number): number
    return price * quantity
end
print(total(4, 3)) -- 12

Add an engine object

Roblox Studio: a separate Script in ServerScriptService. A blue anchored block appears above the origin. Instance, Vector3, Color3 and workspace come from Roblox, so a standalone Luau interpreter cannot run this example.

local block = Instance.new("Part")
block.Name = "LessonBlock"
block.Size = Vector3.new(4, 1, 4)
block.Position = Vector3.new(0, 5, 0)
block.Color = Color3.fromRGB(65, 120, 220)
block.Anchored = true
block.Parent = workspace

Luau: background & uses

Used for
Roblox experiences, Typed game scripts, Embedded scripting
Created by
Roblox and open-source contributors
First released
2021 · standalone open-source release
Version / standard
Continuously developed

Roblox manages its embedded version. Codectionary supports editing and highlighting only; run Roblox examples in Studio.

In the real world

  • Roblox: Experience scripting in Roblox Studio

Facts checked 3 October 2026. Product links describe documented uses.

Best practices

  • Use Studio Output and Script Analysis together: one shows runtime behaviour, the other catches mistakes before execution.
  • Start engine experiments in a new baseplate so you can identify every required object.
  • Learn client/server placement before adding remotes or persistent player data.

Runtime & versions

Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Luau documentation

When should I use this?

Start here if you are new to Luau or know Lua but have not worked with Roblox script placement. Run language-only examples with standalone Luau and engine examples in Roblox Studio.

Common mistakes

Running an engine example in a language-only host

workspace is provided by Roblox. It does not exist in every Luau host.

Incorrect

print(workspace.Name) -- fails when no Roblox engine is present

Corrected

print("Language-only example")
-- Run workspace examples in Roblox Studio.

Compare approaches

  • Lua: Choose the Lua reference for ordinary Lua hosts and .lua files.
  • Luau: Choose this collection for Luau types and Roblox scripting.

Explore deeper

Keep learning

The Luau collection covers language fundamentals and a practical Roblox path, but no guide can cover every engine service. Use Roblox Creator Hub for the latest API details.

Specifications & further reading