Script organization

I recently started on a new game. In the past I’ve given up on games due to them having bad code organization. I’ve tried just throwing scripts wherever, AeroGameFramework, and Knit. With all of them I’ve had unorganized code and I want to avoid this. I know I’ll want to use packages and Luau typing for this project because this game is going to have multiple places.

So how should I organize all of this? Should I just throw scripts everywhere in ServerScriptService and use bindables? Use an already made framework like AGF or Knit? Make my own?

I personally love bindables because it allows you to visualize the responsibilities and features of the objects / scripts they belong to in a quick summary. I know that there are some concerns with bindables because they, for example, serialize tables. But I do think that using them will help in visualizing the features and structure of your project in a clear way and thus help with organization.

Folders also help a ton with structuring your projects, but the more you use them the harder it might become to refactor your organization later down the line if you’re not prepared. In my latest project I’m using a ModuleScript with a function that lists all scripts / modules / etc. within an instance with a method that works as a sort of recursive FindFirstChild method. That has allowed me to reparent instances later on in development without having to rewrite any code and has helped with keeping the project clean.

As for frameworks, I haven’t really used any yet so I can’t give much advice in that regard.

Ultimately, styles differ and everyone will have their own preferences, so you will probably have to experiment a bit until you find an approach that works best for you. But hopefully these thoughts are somewhat useful to you.

1 Like

I think you’re looking for technical solutions for architectural problems - the way Software Engineers learn how to structure their codebases sustainably is through learning design patterns.

There’s an interesting talk from the developers of some of the biggest successful games on the platform at RDC last year: 5 Powerful Code Patterns Behind Top Roblox Games.

The one organisational tip I can give you - when you require a module, it doesn’t re-run every time you require it, instead it just returns what was required the last time. This allows you to save state and stuff inside ModuleScripts. Very useful behaviour!

1 Like

Thanks for the design patterns link. I watched the RDC talk. On the 2nd slide it mentions that I should be using a single script architecture. Would this be a design pattern? Are there any examples of this? Is it just a framework like AeroGameFramework or Knit?