What does the term local mean?
local
sets the variable so that it's only available in the current scope.
in these examples, world is just the name of the function, it could be anything
local a = "Hello," function world() local b= "world!" end world() print(a,b) --> "Attempt to index a nil value (b)"
This happens because b is now only available inside of the function (The scope) where it was created.
The following works because the value of b is created outside of the function world()
, so it can be accesed outside of it.
local a = "Hello," local b function world() b= "world!" end world() print(a,b) --> "Hello, world!"
This works too because b isn't local.
local a = "Hello," function world() b= "world!" end world() print(a,b) --> "Hello, world!"
Another thing to note is that local
variables are indexed a bit faster (barely noticable though)
the term > local means the start of a variable, for example,
local Block = game.Workspace.Part Block.Transparency = 1