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
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.
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.
script.Parent.ClickDetector.MouseClick:Connect(function() 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 part:Destroy()
Easy Written By therDanTDM
See therDanTDM's profile on Roblox