I have what I believe should be a quick question about module script functionality.
I have a game with multiple inventory type items which each have a respective module. There are some other modules in my game (e.g. Cooldown, Vitality, Effects, etc.) which are expectedly going to rely heavily on these ‘core’ modules.
At the moment I am worried about the usage of repetitively requiring these ‘core’ modules into each item module, which are then all consolidated into a ‘control’ script.
Basically I am worried that there will be unnecessary replication of these repetitively used modules. At this time I am using bindable event and functions in scripts which have already required those mentioned modules.
Also I have placed all connections (RBLXScriptSignal) outside of the mentioned ‘core’ models which are repeatably required because i worry that multiple connections will be created by each require(), is this true?
Yes that is one concern, another is that requiring these scripts, possibly 100+ times across other smaller module scripts will become impractical for the server.
I believe that code which only needs to be executed once should not be included in the returned module code that is required. Instead, consider using an Init method or function within the core module scripts, which is called only once. However, if you’re not encountering any problems, errors, or issues with repeatedly requiring the module, there may not be a need to change your project structure.
Requires are cached, so code in it should only run once, but I recommend you use an Init function to keep your code cleaner rather than it just being loosely in the default scope.