Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 2 years ago

What does the term local mean?

0
Do you mean "local" in general, or the actual keyword "local" in Lua? ScriptGuider 5261 — 2y
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 137 — 2y

2 answers

Log in to vote
7
Answered by
RubenKan 3473 Moderation Voter Administrator Community Moderator
2 years ago
Edited 2 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)

Ad
Log in to vote
-4
Answered by 2 years ago

the term > local means the start of a variable, for example,

local Block = game.Workspace.Part

Block.Transparency = 1
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. RubenKan 3473 — 2y

Answer this question