what does it mean to put "local" in front of a variable?
local MyVar = game.workspace.Brick
MyVar = game.workspace.Brick
what does it mean to put "local" in front of a variable?
local MyVar = game.workspace.Brick
MyVar = game.workspace.Brick
Local Variables[edit] A local variable is a variable that can only be accessed by other things in the same scope. A variable is made local by adding the keyword local before the variable. It is true that local variables are obtained faster than normal variables. This is because they are integrated into the current environment they were created in.
local word = "Hello"
A local variable is not visible to things in its outer scope.
if true then -- a new block is created
local b = 2
end
print(b) --> nil
However, they are visible to things in its inner scope.
local b = 2
if true then
print(b) --> 2
end
If a variable has the same name as one in its outer scope, the outer scope's value is overwritten in the inner scope, but not the outer scope.
a = 1
if true then
local a = 2
print(a) --> 2
end
print(a) --> 1
More information; http://wiki.roblox.com/index.php?title=Variable
This discussion is preserved as it was. New answers, comments, and votes are closed.