Your First Luau Code
Part of the Introduction To Luau section of Coddy's Lua journey — lesson 3 of 73.
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 = valueFor 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 5Compare that with chaining .. everywhere — interpolation keeps the text readable while the {braces} do the work of concatenation.
Challenge
EasyCreate a variable named language with an explicit type annotation of string and assign it the value "Luau".
Then print the message Hello, Luau! using string interpolation — a backtick string that embeds {language}.
Try it yourself
-- Write code here
-- 1) declare language: string = "Luau"
-- 2) print the greeting with a backtick string: `Hello, {language}!`
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Introduction To Luau
1Getting Started with Luau
What Is Luau?Why Use Luau?Your First Luau CodeType Checking & Error ModesRecap: Introduction to Luau4Working with Functions
Typing Params & Return ValuesTyping Anonymous FunctionsFunctions Returning NothingOptional ParametersDefault Parameter ValuesVariadic FunctionsDefining Function TypesRecap: Typed Functions2Core Types
Basic Types: num, str, boolThe 'any' Type: Escape HatchThe 'unknown' TypeNil & Optional TypesType Inference in ActionExplicit Type AnnotationsRecap: Core Types Practice5Aliases, Unions, Intersections
Type Aliases for PrimitivesUnion TypesWorking with Union TypesLiteral TypesIntersection TypesCombining Type AliasesRecap: Advanced Type Combos3Typed Tables: Arrays & Maps
Typed ArraysAdding and Reading ElementsWhat is a Map Type?Declaring and Accessing MapsIterating TablesMixed-Shape TablesMulti-dimensional Typed Arraystable.unpack and VarargsRecap: Arrays and Maps