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

What does the term local do? I really want to know.

What does the term local mean?

2 comments

0

Do you mean "local" in general, or the actual keyword "local" in Lua?

0

This is late, but local is a variable.. Basically, if I were to do "local i = game.Workspace", Instead of me having to put "game.Workspace", I just have to put "i".

2 answers

✓ Accepted answer

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

1 comment

0

It doesn't. Read my answer so you know what it actualy does. You don't HAVE to put local infront of everything, but its highly recommended.

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