In Lua, the local keyword means that the given variable is to be stored in a virtual register, rather than the global environment table.
Furthermore, a local variable is limited to the scope that it is declared in, which is why we use them in functions. In Lua it is good practice to always use local variables, because in the long run, locals can be accessed up to 30% faster than globals (due to the fact that globals exist inside of a table that must be iterated over to find the global)
https://stackoverflow.com/questions/9132288/why-are-local-variables-accessed-faster-than-global-variables-in-lua
If you were running code in a Lua shell, you would find out that when you declare a local variable in one line then execute the line, then try to reference that local variable from the new line you will be returned nil. Each line you execute in the shell has its own scope.
In C, variables stored on the stack are local by default. Consider the following C function:
void my_func(void) {
int local_integer = 123;
}
when the function my_func returns to the instruction after the call to it, the variable local_integer will no longer exist because it is limited to my_func's scope. All local variables from a functions scope are de-allocated before the function returns.
This is relatively the same case for Lua.
2 comments
"local" can be a shortcut for a word such as: local Gorilla = script.Parent, you can use it to make shortcut words for lines of code
Variables are shortcuts..... @MrDragonTaker