Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is the difference between variables and local variables?

1 answer

✓ Accepted answer

A regular variable is called a global variable, since it will work globally across the entire script. Global variables are worse on performance and should be avoided as much as possible (I have no yet found a case ware you should favor them).

On the other hand, a local variable is local to it's section of the code. Any portion of your code which is higher then the current stack, or deeper in will not be able to access the variable. For example:

local variable1 = "something"
if true then
	local variable2 = "other"
	print(variable1)
	print(variable2)
end
print(variable1)
print(variable2)

Outputs: something other something nil

Local variables are much better on performance, and generally help to avoid errors caused by variables being defined with the same name.

This discussion is preserved as it was. New answers, comments, and votes are closed.