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

What is 'local'?

I might just sound silly, but no one's ever explained to me what a local is. I'm still learning too, so don't judge me too harshly...

1 comment

0

Questions 6, 345, 350, 557 already address this. Use the search feature before asking something.

1 answer

It confines a variable to the scope that it was defined within, with functions, loops, etcetera creating new variable scopes. For example, if you were to create a function with a local variable, that local variable wouldn't be accessible outside of the function.

Here's an example of this "in practice":

function Scope()
	local CantTouchMe = "Yep"
end

Scope()
print(CantTouchMe) 

What would the above print, given what I said initially? If you guessed "Yep", then you're wrong. It would actually print nil.

1 comment

0

I would like to point out that local variables should be used as often as possible to make code more readable and more efficient.

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