Syntax
local label = if count > 0 then "Available" else "Empty"Examples
Test the actual requirement
Standalone Luau or a Script in ServerScriptService. A count of zero takes the empty branch even though zero itself is truthy.
local count = 0
if count > 0 then
print("Available")
elseif count == 0 then
print("Empty")
else
print("Invalid count")
endKeep a false result
An if expression can return false without falling through to a fallback. The older and/or idiom below cannot represent that choice reliably.
local enabled = true
local value = if enabled then false else "disabled"
local misleading = enabled and false or "disabled"
print(value) -- false
print(misleading) -- disabledBest practices
- Use == for equality and ~= for inequality; = assigns a value.
- Put parentheses around mixed arithmetic and boolean expressions when the intended grouping is not obvious.
- Use and/or short-circuiting deliberately; the result can be a value rather than a boolean.
Runtime & versions
Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Luau documentation