_G accessing question

hello, i have a question about _G table
in pure lua, (and in luajit too) users can access _G content without mentioning _G

example:
script 1:

_G.something = "hello world!"

script 2 (running after script 1):

print(something) -- > "hello world!"
print(_G.something) -- > "hello world!"
-- this is absolutely same

why i cant do same in luau? security?

luau example:
script 1:

_G.something = "hello world!"

script 2 (running after script 1):

print(something) -- > nil
print(_G.something) -- > "hello world!"

this would be great, but not sure why

upd:
please don’t tell me to use modules, i already know it, captain obvious.

if you did that, wouldnt each script have to search through the big _G library thingymabob to check for a variable that they probably dont need

theres probably some sorta optimized way to do this but either way its extra workload that could cripple big games (not the company that sues people for using square pets in their games)

1 Like

I would not recommend using _G. or shared. as they are slower than just using modules performance wise. You also don’t get intellisense with _G or shared.

Just use a module to store variables such as

local tbl = {
    something = 'Hello World!'
}

return tbl
local tbl = require(path-to-module)
print(tbl.something) --> Hello World

Im not sure, but that’s what roblox wanted ig. Probably for security reasons or more manageable scopes.

Though I would not recommend using _G as it’s kind of slow, just use regular modules if you really wanted to.

Also roblox is experimenting with going off platform because you can now require modules with a string, like in other languages and environments, so they might add this back(or not).