Need help with a way to reformat my code

Hello, I have been working on a game for the past 2 months, and i just realized a big error i made when originally working on the game. The main framework of the game is a local script that uses _G functions to be used in other scripts. I do not know how to go around reformatting this as a lot of the functions are used for various things around the game. I mainly want to fix this because _G is just a bad practice and i want to practice single script architecture but cannot understand it well enough to start as I have never had to do anything like this before, most amount of reformatting I have done would be a simple error. Any ideas are appreciated. :slight_smile:

2 Likes

You could use module scripts instead of using _G. And yes you’re correct, _G is indeed deprecated.

1 Like

How should i go about doing that? Should I just take every _G function and put it into one module script or should i make like 3 separate module scripts for the stuff like shops, dialogue, etc?

Sorry for such a late response. Anyways, I personally would make three separate module scripts but you’re free to make your own choice (you could have multiple useful functions in one module script).

1 Like

Turn this localscript into a modulescript which will be the core of your framework. Inside the module script convert all _G functions as methods of the modulescript. Now you can require this modulescript from all localscripts, store it in a variable and then replace all _G in your scripts with the said variable name.

1 Like

Should I put the module scripts into replicated storage? I don’t know if exploiters can edit module scripts or not so that’s why I’ve strayed away from using them until now.

Exploiters can Decompile ModuleScripts, so I Recommend that you place very Important Modules within ServerScriptService or ServerStorage, which are Containers that dont Replicate its Contents to the Client, if you need the ModuleScript for both Server and Client , then place it in ReplicatedStorge, but be careful with what you are doing with them

Thats not a very good reason to stay away from them, They are very useful with Code Organization, and Object Oriented Programming, you were missing out. :frowning:

3 Likes

Depends on your needs. If the functions are to be shared across the server and client, place it in ReplicatedStorage, if the they are server specific, place em in ServerScriptService and if they are client-specific, chuck them in StarterPlayerScripts.

2 Likes

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