
There are mathematical operators for addition, subtraction, multiplication, and division. Operators allow us to define code that changes a variable’s value. To avoid any confusing issues or bugs in your code, it’s always best to declare your variables with local. In this instance, the multiplier variable becomes a global by defining it without the local keyword.Īdding this to the end of the script executes just fine. Mis-using global variables may lead to confusing behavior in your script. It is important to carefully use global variables since any other script can access them. Variables in a global scope exist until the entire program finishes. Within the function multiplyByFive(), the multiplier variable exists until the function finishes and does not exist outside of it.Īdding this to the end of the script would fail.

In this example, the variable ‘a’ exists in memory until the script finishes. If this doesn’t happen then our programs will use up all the available memory and eventually crash your computer or device. Once the script finishes, these variables get cleaned up by releasing the memory used. Variables with a local scope only exist until the function or script finishes. Scopes help organize your variables and help to control allocated memory. You can have variables in a local or global scope. ScopesĪ scope determines how long a variable exists in memory while the script is running. The best way to think of nil is that the value does not exist. You might think this is zero but it’s not. TypesĪ variable uses the nil type when it should have no value. Dynamic typing means that a variable can store any type of data. You can of course create your own object and add a script for it using the same steps. This is a quick way to get started with Roblox scripting.


