Skip to content

Lesson 1: Introduction to Luau

Goal: read and write the Luau you need for scripts. This lesson uses only the language, not SwizzinIRC.

local function double(n: number): number
return n * 2
end
print(double(21)) -- 42
local words = { "classic", "irc" }
for i, w in words do
print(i, w) -- 1 classic, then 2 irc
end
local greeting = `Hello, {words[1]}!` -- string interpolation with backticks
print(greeting)

double is a function that returns a value. The for loop walks a table. Backtick strings insert values with { }. Inside SwizzScript, print writes to the Script Console, the same as swizzin.log.

The sandbox provides coroutine, table, string, utf8, math, bit32, os (time and date only), buffer and vector. It removes require, load, dofile, io, debug, package and similar. See Luau fundamentals.

Running this as a script shows 42, the two list lines and the greeting in the Console tab of the Script Manager.

  • Forgetting local, which makes a global.
  • Tables start at index 1, not 0.
  • Not-equal is ~=, not !=.
  • Trying to require another file: scripts cannot load other scripts.
  • attempt to call a nil value: a name is misspelled, or the function is defined later in the file.
  • Nothing appears: the script is Off. Turn it on in the Script Manager. See Script errors.