Search results
6 lip 2024 · Putting local in front of your variable name just describes its scope. If you don’t put local, it makes the variable global. Global variables can be used by any part of the script, rather than with local variables, which only that specific block can use it.
- Scope
Local Scope. Luau can only access a local variable or...
- Scope
25 gru 2021 · A local variable is accessible only in the block where it’s declared. A (non-local variable) is visible to all scopes of a script. In the following code. create.roblox.com
The local keyword defines the scope of the variable or function. Take the following example: local var1 = 10 if true then local var2 = 5 end print(var1) print(var2) --Output --> 10 --> Error: Variable not defined.
18 mar 2023 · What is the difference between a “local” variable defined directly in the script and a “global” variable defined inside a function. It seems like we have 2 different variables with the same name “x” here?
This would be called the block scope, and those variables are only accessible within their block (such as a loop). Hopefully this cleared it up a bit. TLDR: break up your code into functions, always use local, and local confines something to its scope.
Local Scope. Luau can only access a local variable or function in the block of code where you declare it. Creating a variable with local scope gives you tighter control over when and where its value changes. In the following code, the testFunc () function and testVar variable have local scope.
Scope. In Luau, you can write variables and logic in a tighter scope than their function or class by nesting the logic within do and end keywords, similar to curly brackets {} in C#. For more details, see Scope.