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

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

difference between

local variable =

and

variable = 

2 comments

0

i don't think that 'variable' actually creates a variable. 'local' speicifies that a vaiable is created

0

Try to use local variables as much as possible, because global variables increase latency in your game, which none of us want, right?

1 answer

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

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