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

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

Asked by 8 years ago

What does the term local mean?

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

2 answers

Log in to vote
7
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
8 years ago
Edited 8 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 8 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 3615 — 8y

Answer this question