If you could share the way you’re doing it, we could give some direct advice.
Answer
But in general, there is no “best” code structure. It all depends on how big your game is, whether you want to organize it modularly, whether you want intellisense, etc.
About frameworks
You often hear of “frameworks” like Knit which are a way of structuring your code made by other people. Knit’s syntax is easy to learn and has its own built-in way of managing RemoteEvents easier., but it sacrifices intellisense because of its module loader and is considered outdated.
There are also frameworks for UI like Fusion and Roact which you can look into. Though I hear the learning curve is a bit higher for Roact.
Other than Knit, I’m not too particularly knowledgeable in other frameworks, but definitely look into those.
My approach
I have a Modules folder in ReplicatedStorage and ServerScriptService where I keep all of my modules. A script/LocalScript requires all of them and calls start().
For networking (RemoteEvents, etc), I use Packet (really good).
Heirarchy:
Further explanation
- The Shared folder is where I keep a Config module for all customizable settings in my game (intermission duration, for example), and a Packets module to hold RemoteEvents through the Packet library.
- The Util folder is just accessory modules I’ve made specifically for the game
- The Packages folder contains modules/libraries by other people (I.e, ProfileStore).
My framework is still in development. I’m still thinking of how to organize class modules, how to manage my UI, etc.
My opinion
I suggest trying out several frameworks first if you think of making your own. It’ll give you much insight into how a lot of people like to organize their code and you can apply those to yours.
The way to improve code structure is to take in parts of what other people have, learn from their mistakes, and apply it to your own.
