Easy Written By therDanTDM

How to use variables Created on: 01-01-2019

In this tutorial you'll learn about variables

Hello, I am therDanTDM and today we'll learn all about variables.

A variable means something that is liable to change. Variables are like shortcuts to an object in the game. There are two types of variables in Lua:

global variables local variables

myvariable = workspace.Part --global variable
local myvariable = workspace.Part --local variable

Global Variable:

myvariable = workspace.Part --A variable can be named anything. This
--is a global variable.

A global variable is a variable that does not need any declaration. It can be accessed from any block of code and is only used in an enclosing function.

Local Variable:

Unlike global variables, local variables have their scope limited to the block where they are declared and they need the declaration 'local' before being used.

local myvariable = workspace	.Part


--This is a local variable  used in a function. Here using a global
--variable will throw an error


--If you use a variable, you don't need to type the entire
--thing, just the variable name. Example:
part = workspace.Part


Easy Written By therDanTDM

See therDanTDM's profile on Roblox