Unit 6: Control Structures
In Lua, the if
statement allows you to execute code conditionally. The basic syntax is:
if condition then
-- code to execute if condition is true
end
The condition is evaluated, and if it's true (any value other than false
or nil
), the code inside the if block is executed.
local playerHealth = 50
if playerHealth < 100 then
print("Player is not at full health!")
end
==
~=
>
<
>=
<=
local playerLevel = 10
if playerLevel >= 10 then
print("Player can use advanced weapons!")
end
In Roblox, if statements are commonly used to check player conditions, part collisions, and game states.
Create a function that takes a player's health value and returns a status message based on the health value.