Best approach for modules to interact with eachother?

You organize the modules into separate folders. My typically setup is shared, general, managers, then services. The manifest says which order to load each category, and then also says what to initialize first in each folder. (Whatever is explicitly typed in the manifest is loaded in that order before the rest of the folder contents). shared is a folder referenced in replicatedstorage that contains important modules for both client and server. Can’t share any code as there’s a lot more complexity to mine that I’d like to keep private atm, but that’s the general gist of it.

1 Like

Another solution, if you don’t want to refactor a tonne of your code base (and again, don’t structure your games so you need to do this!!! This is whack, but occasionally useful), is to require it just after the module is loaded like this

local ServerWeaponHandler 

coroutine.wrap(function()
    wait()
    ServerWeaponHandler = Novarine:Get("ServerWeaponHandler")
end)()

Obviously this comes with its own set of risks and you need to take extra precautions to make sure you don’t try to use something the script hasn’t loaded in yet. But it is more performant than my other method, although the improvement is slight

1 Like

I decided to re-evaluate how I’m using ProfileService and have came up with the following:

Instead of storing player profiles in the same ModuleScript that should only be called once to initialize, I’m now storing profiles in a separate ModuleScript that contains all active profiles in-game. I can reference the module at any given time and theoretically shouldn’t run into any cylical require issues because it isn’t dependent on any other modules.