I want to load functions into _G

Hello
I want to load functions into _G
but how do I make sure that the functions are really loaded into _G before I use them

I DONT WANT TO USE MODULE IM TRYING TO LEARN _G

Don’t do that. There is not a good reason to do that. It exists exclusively for very specific debugging tasks that are meant to be used once and then removed. What is the information you are trying to share with _G and where does it need to be accessible from?

One of deepwoken devs uses it regularly and i want to understand why
and how she is able to load function safely into it

plus its convenient to use in codes

They use it because they don’t know better, or their code already uses it so extensively that it would be difficult to change. If you do this, your code will become dramatically more difficult to debug. Do not do it.

Usually you would just use _G for Variables to send to Scripts on the same Context Level, But Some might Recommend that you use ModuleScripts Instead.

2 Likes

It is convenient as long as only one operation, preferably a temporary test, uses it. Once you use it for multiple things it becomes a huge mess. Do not do it.

Use ModuleScripts instead – Roblox scripts run sequentially making _G a bad idea. For example, say you have 2 scripts utilizing _G

  • Script 1 defines a function in _G
  • Script 2 attempt to read and execute the predefined function that script 1 sets in _G

This may seem perfect at first glance, but what if script 2 runs before script 1? The function will be nil and an error will be thrown. The only way to really fix this is yielding the threads of scripts reading _G variables which is sloppy

Take a look at this article for another example: _G. variable appears nil? - Scripting Helpers

3 Likes

Ok thank you
I wanted to believe it too but when I saw the dev use it
I had existential crisis I started to doubted everything i know fr

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.