Beginners Scripting Guide (BETA)
  • Getting Started
  • Basic Data Types
  • Variables
  • Basic global functions
  • Number Arithmetic & Compounds Assignment
  • If statement
  • Function
  • Table & Dictionary
  • Loops
  • Creating An Object
  • Understanding Client & Server
  • RemoteEvent
  • Unfinished & In-progress
    • Methods
    • RemoteFunction
    • Basic libraries
    • Basic Services
    • Basic of Vector3 and CFrame
    • Basic built-in events
Powered by GitBook
On this page
  • NAMING VARIABLES
  • RESERVED NAMES LIST
  • GLOBAL & LOCAL VARIABLE

Variables

✏ Beginners Scripting Guide ✏

PreviousBasic Data TypesNextBasic global functions

Last updated 11 months ago

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
https://create.roblox.com/docs/luau/variables