How should I organize my explorer window hierarchy to fit the needs of a lot of OOP objects/scripts that share functionality?

I’m at a complete loss, I’m not sure how to handle organization in a way that isn’t too organized to the point where there’s only one module per folder (creating clutter) but isn’t so disorganized that it’s general clutter.

I have some features in my game and I don’t know how to organize them so they all handle their respective functions but while also working together.

Here are the features:

  • Players have their own base where they can build whatever they want.
  • Crops grow outside of the players base and randomly in the world, players can cut them down and sell them for money.
  • Players have an inventory system for better crop harvesting tools, as well as cash, and as well as a storage system to store all the objects they don’t want to place on their base yet.
  • All objects in storage can be traded with other players.
  • There are multiple stores that sell equipment or things you can put in your base.
  • A movement based anti-cheat.

The issue is some of these features are completely independent but share some of the same functions.

For example, I have two big tables, one is for crops and the other is for player property. Every time a new crop is spawned, it’s added to this table and it holds data like what it is, how much it sells for, etc. What’s added to the table is also an OOP object, so I can call :Grow() or :Die() on the crop. The second table is player data, which also uses OOP, so I can call :Save() or :Cleanup() on it if needed. The issue is both of these tables are completely different but they share some similar aspects like ownership.

Each crop is technically ‘owned’ by nobody until a player harvests it. Every time data is added it’s ‘owned’ by the player who loaded their data, as it should. Anyways, I have a function that searches tables for owners and the problem is that where should I keep this function? The script that handles crop growth and ownership is far different from player data so I can’t just merge these two big scripts.

Even if I tried putting everything ‘under’ data, because technically all the stuff in my game could be considered data-oriented, it would end up looking like this ugly mess:

image

Now this already looks ugly. If PlayerData and Crops use the same function, it can’t be localized or else I’d have to write it twice and that would be a pain to update if I needed to.

This doesn’t just end with one function however.

What if far in the future I have hundreds of functions shared uniquely between 2-3+ scripts? Where am I supposed to organize these? If I keep putting more functions under the scripts that use them, eventually the explorer will be impossible to read. It’d get even uglier if I wanted to include more than just shared functions under a script. What if I needed to include new but shared classes? Or shared assets?

image

I then decided on this, which looks good at first. It’s a folder parented to ServerScriptService called Shared that allows multiple scripts to use one function without having to go through tons of parents or children assets to get there.

The issue with this now is what about functions that are only shared between two scripts? In the picture above there are two Crop modules. Crops can be saved to your base, which is apart of data, but they can also spawn naturally, which is apart of the crops growth engine (simply labeled Crops above).

I can possibly unify these as one under Shared, but then that folder just becomes the problem from the first image? I’d eventually have to create a new shared folder for my pre-existing shared folder because some of those functions could be sharing functions and I wouldn’t want to run into load order problems.

The problem, in my eyes, seems never ending. All my features use each other but aren’t all using each other. If I have a function used by both the Anticheat and Data engine, but not used by the crop engine, why should I put it in a shared folder? How can I organize my explorer window so shared functions, classes, assets or variables between two engines, or between two classes, or between whatever really, won’t clog my explorer?

Any advice helps, and please if you want, share photos of decently organized ServerScriptServices or even ServerStorage. Please don’t link tutorials or other topics unless it will actually solve my problem, I guarantee I’ve seen every organization topic on this site and a handful of organization videos for Roblox oriented programming.

Also if necessary I can provide real examples of these issues and why these images can become a reality if I were to follow their etiquette.


A lot of this was rambling because I couldn’t figure out a solution for a long time. Turns out the solution is single-script hierarchy. I was able to visualize it in a way that suits my experience by using an open-source project as a guide. Thank you, @Imaginaerum, for indirectly solving my madness.

1 Like