Question about Variables

So, I just wanted to know, what is the difference between the no local and local variables. Example:

number = 1 -- No local
local number = 1 -- local


Basically, the big idea is that without local, the variable is defined and can be accessed anywhere since it is not restricted to a scope or in other words, where it is located in a script. When it is local, it is restricted to where it is, whether it’s in a function or event listener.


Ahhh., I get it now. Thank you very much!

For the record, you should only use local variables. This is how most languages operate, and they have the benefit of being more efficient. Using the non-local ones can result in buggy code because you have no control over accessibility.


if you were trying to define something within this script only, yes.

if you needed to have multiple variants of the same variable, like X and Y be used in multiple scripts.

x = 1
y = 2

local is when you are doing it in a singular function and non local is a variable for the entire script, don’t know how else to describe it