Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

what is the difference between making a local variable and just a variable?

Asked by 6 years ago

difference between

local variable =

and

variable = 
0
i don't think that 'variable' actually creates a variable. 'local' speicifies that a vaiable is created killzebra312 -7 — 6y
0
Try to use local variables as much as possible, because global variables increase latency in your game, which none of us want, right? KingLoneCat 2642 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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.

Something neat about local variables is that they don't seem to really overwrite over a different variable of the same name

Example:

local myPart = Instance.new("Part")
myPart.Name = "Part1"
myPart.Parent = workspace
print(myPart.Name)

do
    --NOTE: This is a 'scope'
    local myPart = Instance.new("Part")
    myPart.Name = "Part2"
    myPart.Parent = workspace
    print(myPart.Name)
end

print(myPart.Name)

The source below should shed some more light on that, scopes and stuff.

Source: http://wiki.roblox.com/index.php?title=Variable

Ad

Answer this question