Menu
CoddyTech

Your First Luau Code

Part of the Introduction To Luau section of Coddy's Lua journey. Lesson 3 of 80.

Time to write your first Luau code! The new ingredient on top of the Lua you know is the type annotation: a colon and a type name after the variable name.

local variableName: type = value

For example, a variable that should only ever hold text:

local message: string = "Hello, World!"

The : string part tells the type checker that message must contain string values. Try to assign a number to it later and the checker reports an error while you're still editing.

Luau also gives you a nicer way to build output: string interpolation. A string written with backticks can embed any expression inside curly braces:

local name: string = "Coddy"
print(`Hello, {name}!`)        -- Hello, Coddy!
print(`2 + 3 is {2 + 3}`)      -- 2 + 3 is 5

Compare that with chaining .. everywhere: interpolation keeps the text readable while the {braces} do the work of concatenation.

challenge icon

Challenge

Easy

Store the language name in a typed variable and greet it.

  1. Under the comment, declare local language: string = "Luau".
  2. Change the print to a backtick string: print(`Hello, {language}!`).

Press Run Code: the output shows Hello, Luau!.

Try it yourself

-- Declare language here

print(``)

All lessons in Introduction To Luau

Practice on your own: Online Luau compiler