I do not know how to use global variables.
I am using a while loop and using a variable to determine whether or not it is true.
I want to change this variable through another script, although I need to use a global variable for that I believe. But I cannot use a global variable because I do not know how to use them.
Can I please get some help with this.
_G.Apple = true
while Apple == true do
It says that Apple still is undefined.
Your mistake here, is that you are trying to reference Apple without defining it, meaning that you have to use _G.Apple
Instead of
while Apple == true do
Try it like this.
while _G.Apple == true do
Hello.
Globals:
There are two kinds of global variables.
These variables should be avoided unless you have a specific reason to use them.
Example:
local function myFunc() message = "Hello world!" end myFunc() print(message)
If we had a "local" before declaring the variable on line 2, it would print nil as of local variable scope.
_G
.These variables are variables that can be shared across all scripts, except client to server.
Here is your fixed script.
_G.Apple = true while _G.Apple == true do end
You just forgot to write _G
before writing the "Apple" variable.