What are some good techniques that I can employ with my games for better organization?

I’m trying to fix my organization for future games.

Currently, I divide scripts into modules, and classes, and a respective manager script that manages each module. I feel like this isn’t the best way to do it, but it’s how I do it.

I’m in the process of researching ECS (Entity Component Systems) for better organization, and to structure my projects better. I wanted to experiment and try to create something with that, just to see how it felt, as I’m familiar with the term: Composition over Inheritance, and how you’re not supposed to use inheritance in areas that composition would prove to be better.

I’m trying to get better at scripting, and I thought I should ask around, and try to see how other people do things, so I can learn from it.

So, if you have some pointers into improving my organization, or just want to show me how you organize, I would greatly appreciate it.

I’m sorry if this question has been asked before, I just want to personally ask, and find out how others organize things.

1 Like

Finite State Machines are pretty good, you should try them out!

1 Like

Don’t overthink it too much. No need to use ECS if you don’t need to. Only case were ECS on roblox would be helpful or largely better is if you had a really big RPG game with thousands of entities.

I would look into SSA and make sure you understand OOP & metatables. I find that those techniques help make things more organized (personally).

I would also research decoupling and abstraction so that you know when to make new scripts or separate logic.

Don’t assume that there’s only one right way to do it. You could have 500 different scripts or just one. Whatever works best and is most intuitive for you (or your team) is the way to go.

I’ll show you how I personally do it though, just in case it interests you:

I have the ServerHandler and the ClientHandler which are the two main scripts. Below that are module scripts that act as handlers for each major gameplay element with subhandlers for organization and various tasks.

I have a dedicated folder for stuff like types, enums, and allat just to keep it in one place.

2 Likes

You should look into module loaders check out these videos:

2 Likes

I do tend to overthink the way games should be structured, since I don’t want to make the same mistakes of having my games unorganized and scripts being sprinkled around.

I was actually looking into SSA, I was thinking it would be better to condense a lot of the module requiring, setup, and initialization into a singular place, instead of various scattered managers.

I appreciate you sending how your structure looks, it looks very neat and organized, I’m wondering, do you not use specific class modules? Or do you just treat modules as classes without naming them as such.

I understand OOP, but not on a deeper level. I use metatables, but I haven’t really experimented with many of the metamethods that surround metatables, since I primarily use the __index method.

I’ll start researching decoupling and abstraction, since my main issue, was definitely trying to create reusable systems, since a lot of my modules had to be rewritten a little bit. I’ll make sure to keep my classes, and modules less rigid, and more decoupled from things that require them.

I’m only worried since, I love learning new techniques, and ways to improve my coding habits.
I don’t want to be stuck doing the same thing. Unwilling to change how I structure, and design my games, and their code.

Thanks for your time, and I appreciate you replying to my question!

I did previously watch the video about script organization, which actually was one of the contributing factors why I made this post.

I wanted to see how people actually utilized a lot of the techniques they use, and if it was fully worth swapping over to anything they mentioned, or if I should keep my regular structure.

I only hesitated to implement SSA, because I saw all the services and wondered how cluttered it would be, but I also don’t necessarily have to follow the way it’s made, just the concept of using a single start/initialization script.

I’ll take a better look at the module loader video, as I watched it a few months ago, when I didn’t fully understand modules.

Not using bloatware, people propose and rely on super-optimized but self-contained scripts.

That it
ECS is just a pattern
Functional programming is the main tool.
Everything else is bias, half-truth and noise.

1 Like

module loaders are USELESS. Don’t use them, it’s a waste of time

3 Likes

this should summarize it

1 Like

It’s literally reinventing the wheel :wilted_flower:
If you don’t use a module for a shared value, it’s effectively useless.

3 Likes

“do you not use specific class modules? Or do you just treat modules as classes without naming them as such.”

If you’re talking about OOP classes, I only use them when necessary. It’s not in my structure but I OOP-oriented scripts lying around somewhere. Like others said, OOP is not native to roblox so I try to limit its use but it’s not like it’s going to ruin your game or anything so I just use it when I feel it’ll be helpful. Most common use cases of OOP is when you need to apply common behavior to a lot of instances as you probably already know. I also mentioned you should know metatables but I was really only talking about functions closely related to OOP. Nevertheless, I do find that knowing a bit of metatables can actually be helpful for other parts of development. EX: you can use OOP + metatables to do something like

local Inventory = InventoryClass.New(Player,PlayerData)
Inventory + "Apple"

Inside the inventory class, there is an addition handler where if you try to add something to the class, then it handles it in a custom way, taking in the added parameter, “Apple,” and adding it to the player’s inventory. (__add metamethod)

Anyways, back to the topic of script organization,

I was actually looking into SSA, I was thinking it would be better to condense a lot of the module requiring, setup, and initialization into a singular place, instead of various scattered managers.

How I handle that is, I have a Players script in my structure under ServerHandler as you can see. Under it are modules such as “Data,” “Character,” etc. each submodule handles various tasks related to the Players. All submodules have the function “PlayerAdded” that is called when the main handler (Players) detects a new player. The Data subhandler handles all the data setup and management while the Character submodule loads the character and applies whatever is needed. The cool thing about this is that you can have sub-sub-handlers under the Character submodule that Handles Character-related stuff. To visualize:

Players
→ Data
→ Character
–>–> Accessories
–>–> Attributes

I also do acknowledge how others said that

If you don’t use a module for a shared value, it’s effectively useless.

And they’re not wrong. However, I feel that their approach is a bit black and white. What I like about module scripts is their ability to act as shared values or as standalone scripts. So what I often do is I combine them. In my previous example, my Data subhandler can automatically handle all data requests as a standalone script while having functions inside of it that can be called for specific events such as PlayerAdded to set up the data. To illustrate:


local DataHandler = {}

function DataHandler.PlayerAdded(Player)
-- setup Player Data stuff
end

Network.DataRequest.OnServerEvent:Connect(function()
--ability to handle independent data events
end

return DataHandler

You can do the same thing with normal scripts but they require remote functions or someting like that. But it’s just a bit harder imo, not to mention having nested scripts/local scripts can be messier than module scripts. That’s another reason why I prefer to use module scripts in my aforementioned structure.

I would say that once you find a structure you like, to just stick with it. It’s good to know how to work around various structures (especially for commissions) but having a structure you really “own” speeds up development for me since you already know where everything is and how the scripts work/connect. Until then, just mess around with different structures until you find one that feels right to you. A good way to do that is through working on different games and trying out their structures. That’s how I found the structure I like most.

Also, please don’t use ECS unless you’re building a huge RPG game with thousands of entities. It’s literally useless and will waste your time otherwise.

Good luck on your scripting journey! Let me know if you have further questions.

1 Like