What does this mean?

i was in a youtube video and i have a question…

What Does Mean " _G"
?

And someone can explain what is coroutine?

1 Like

_G Its Global Variable can use it in every script but local in one script
script 1

_G.Hello = "Hi"

script 2

print(_G.Hello)

a coroutine is used to perform multiple tasks at the same time
so you can use 2 while do in one script and all of them work like in this script

local test = coroutine.create(function()
      while wait(1) do
         print("Hi")
      end
end

coroutine.resume(test)

 while wait(1) do
    print("Test 2")
 end

coroutine: coroutine

So on multiplayer games there is this “client server model” where there are clients (aka your computer and other people’s computers that are playing the game) and then there is a single server (at least for Roblox). The server acts as this mediator that handles save data and other things.

_G is a device-sided table. In other words, on a Script in roblox it would be the same for all the Scripts.
On a LocalScript though it would be the same for the same client but not replicated to other clients.
Basically it’s a universal table that is not replicated across devices. It can be accessed from scripts running from the same device.

Script1:

_G.H = "Hello world"

Script2:

repeat wait() until _G.H
print(_G.H)

Crude answer for coroutine is that it runs an independent thread. All Scripts and LocalScripts are ran on their own thread I believe. So it starts another thread without it being in a different script.

_G represents the global environment, it’s a table value where global variables are held. Roblox has its own global variable named “shared” which shares the same behavior as Lua’s _G. Which you ultimately use is entirely optional.

“G_”'s definition in relation to Roblox can be found here:
https://developer.roblox.com/en-us/api-reference/lua-docs/Lua-Globals

“shared”'s definition can be found here:
https://developer.roblox.com/en-us/api-reference/lua-docs/Roblox-Globals