New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
0

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

What does the term local mean?

0
Do you mean "local" in general, or the actual keyword "local" in Lua? ScriptGuider 5471 — 3y
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". crywink 419 — 3y

7
RubenKan 3570
3 years ago
Edited 3 years ago

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)

local Block = game.Workspace.Part