LuaU Beginner's Guide

LuaU is a scripting language derived from Lua. The language is mainly used by Roblox game developers to write code. The language is designed to be small, efficient, fast, and safe to use. LuaU is a great language for beginner programmers because of its simplicity. I really hope you find this free course helpful in beginning your journey!

Information on this page was found on Intro to Luau: A Beginner's Guide - HackMD

SECTIONS:

COMMENTS

  • LuaU will ignore lines of code when prefixed with certain characters.

  • In comments, you can write anything, and it doesn't have to follow the code grammar.

HOW TO WRITE COMMENTS:

  • Single line comments are prefixed with --

  • Multiline comments are prefixed with --[[ and end with ]].

EXAMPLE

SERVICES

  • A service is an object that contains built-in properties, functions, events, and callbacks.

  • Services are used to reach a goal.

  • EX: DataStoreService is used to handle data within the game and save a player's progress

HOW TO CALL A SERVICE WITH A SCRIPT:

  • ServiceProvider:GetService()

EXAMPLE

SCRIPTS

  • A Script is the container for your LuaU code.

THERE ARE 3 TYPES OF SCRIPTS...

Local Scripts (LocalScript)

  • Used for executing LuaU code on the client

  • These scripts do not run when parented by a service owned by the server.

Server Scripts (Script)

  • Used for executing code on the server

  • These scripts do not run when parented by a service owned by the client.

Module Scripts (ModuleScript)

  • Need to be required by either a Server Script or a Local Script in order to be run.

IMPORTANT NOTES

  • ReplicatedStorage is neutral to both Server and Client scripts

  • ServerScriptService and ServerStorage are invisible to the Client

  • ReplicatedFirst is invisible to the Server

VARIABLES

  • A Variable is a name that represents another Value.

  • Variables can be a Number, String, Boolean, DataType, etc..

  • There are two scopes for Variables: Local, and Global.

HOW TO DEFINE A VARIABLE:

  • Local x = 1 [Can only be used in local scope]

  • x = 1 [Can only be used in the script it is defined in]

  • _G.x = 1 [Can be used across multiple scripts]

  • local x, y, z = 1, 2, 3 [Defining multiple variables at once (x = 1, y = 2, z = 3).

  • a, b, c = 1, 2, 3 [Defining multiple variables at once (a = 1, b = 2, c = 3).

Functions

  • A Function is a set of instructions that can be used multiple times in a script.

  • Can be executed through command or triggered through an event.

HOW TO DEFINE FUNCTIONS:

  • A basic function uses the function keyword, followed by two parenthesis ().

When called, functions will execute the code within the body of the function. To call a function, simply type the function's name and end with two parenthesis: add()

EXAMPLE:

Arguments & Parameters:

  • A Parameter is a variable listed inside the parentheses in the function definition

  • An Argument is the value that is being sent to the function whenever the function is called

Return a value:

  • Return is often used to return a specific value within the function

CONDITIONALS

  • Conditional Structures are what give scripts the ability to perform actions when a specific condition is true

  • Conditions can be checked with the following operators...

IF STATEMENTS:

  • == Is Equal To

  • ~= Is Not Equal To

  • > Is Greater Than

  • < Is Less Than

  • >= Is Greater Than or Equal to

  • <= Is Less Than or Equal to

EXAMPLES:

  • Booleans, Strings, Data Types, and Numbers can all be affiliated with the relational operators.

  • Booleans and Strings only use Equals to and Not Equals to operators.

NUMBERS:

BOOLEANS:

STRINGS:

FUNCTIONS:

ELSE STATEMENTS:

  • When the conditions of the if statement are not met, you can use an else statement.

  • Conditional structures cannot start with else statements.

EXAMPLE:

FINISHED!

I hope you found this free guide useful! Be sure to check out my Youtube channel and other free products on this website!

-DeHapy