Chapter 1: Variables, values and types Chapter 2: Properties and Instances Chapter 3: Conditionals and If Statements 3.1: Conditionals 3.2: If Statements 3.3: Using If Statements Chapter 4: Functions and Blocks Chapter 5: Event Listeners
3.1: Conditionals

A Conditional is defined by Oxford Languages as: subject to one or more conditions or requirements being met; made or granted on certain terms.

In programming, a conditional means the same thing, where a certain condition needs to be met for something to happen.

Conditionals can take the form of many different things, but the most prominent are If Statements which will be further discussed in the next section.

3.2: If Statements

If Statements are a type of conditional, where if a certain criteria is met, something happens. An example of an if statement could be, if playerx has 500 coins, then playerx can buy a sword.

If statements are particularly powerful in scenarios explained above. They allow for logic to take place in programming.

LUAU makes If Statements incredibly simple, since they are written the same way they would be written in English.

3.3: Using If Statements

Before understanding how if statements are written in LUAU, we first must understand that each section of code must involve an end to indicate the end of that section. An end must also be included with if statements.

if CONDITION then
--Do Something
end

We need an end so the computer can understand where our if statement ends. Otherwise, the computer would not be able to differentiate.

We can use if statements with any comparison based value which we have discovered in Chapter 1. This includes, but not limited to, booleans, numbers, and strings.

if 10 > 7 then --This will "Do Something" if 10 is greater than 7, which it is.
--Do Something
end

if boolean == true then --This will "Do Something" if the boolean value "boolean" is true.
--Do Something
end

if name == "Bob" then --This will "Do Something" if the variable "name" is "Bob"
--Do Something
end

As we can see above, there are many different ways we can use If Statements which make them very useful.

Chapter 4: Functions and Blocks