Variables
✏ Beginners Scripting Guide ✏
https://create.roblox.com/docs/luau/variables In this section, we will discuss variables. A variable is a name that can hold data types such as booleans, numbers, strings, etc.
NAMING VARIABLES
When naming variables you CANNOT use space, number, and reserved names.
local myVariable = 'string' -- valid
local my_Variable = 1 -- valid
local my1stVariable = true -- valid
local 123 = 'string' -- not valid
local my variable = 1 -- not valid
local if = true -- not valid
RESERVED NAMES LIST
RESERVED NAMES
and
for
or
break
function
repeat
do
if
return
else
in
then
elseif
local
true
end
nil
until
false
not
while
GLOBAL & LOCAL VARIABLE
A variable can be GLOBAL and LOCAL. GLOBAL means it can be accessed everywhere in the script and LOCAL means it can be only accessed in a certain block of codes.
GLOBAL:
if 1 > 0 then --- if 1 is greater than 0 then the code will execute below.
myVariable = 'Hello, World!!'
print(myVariable) -- Hello, World!!
end
print(myVariable) -- Hello, World!!
LOCAL:
if 1 > 0 then --- if 1 is greater than 0 then the code will execute below.
local myVariable = 'Hello, World!!'
print(myVariable) -- Hello, World!!
end
print(myVariable) -- nil
Last updated