Should I use modules only in client sided game?

I’m planning to work on a single-player story game soon. But I’m torn on whether it would optimize the game better or make the game run any better if I use Module Scripts to run the entire game, the only example I can think of is the way Pokémon Brick Bronze was structured and developed; Or If I should use bindable events and local scripts for all the functions.

If not those two, then what would be the best way to structure and develop the game?

Yes, you should use modules.
Eventually you probably will use server sided stuff (for example, if you want a NPC humanoid to die, you need to implement server sided damage) but modules are also great for DRY (don’t repeat yourself) so you can change your code more easily.

1 Like

In terms of optimization I don’t think it’d matter, but when it comes to organization and being able to change your code easily, you should use modules

1 Like

No, your game wouldn’t run any better, in fact don’t quote me on this, it might be possible that your code runs slightly worse to the most MINISCULE degree since.

The reason and logic behind making your code more modular down to 3 main categories:

Abstraction

When you’re writing code, it’s hard for people to make any necessary edits to the code, and especially with variables and other things, it becomes hard to see what’s doing what.
With modules, it’s much easier to create getter and setter functions that are labeled precisely to what they are intended to do.

Also it makes the use of utilities so much easier.

Searching

When you are searching for a specific function or something of that nature when working with a 2000 line script, it is very inefficient (You probably noticed by now).

By using modules, you can easily separate big chunks of code, and have a much easier time finding and editing something in your code that meant to be changed.
Now don’t fall into the trap of creating a new module for every single block of code, b/c that makes it difficult to find certain modules, defeating the whole purpose altogether.

Functionality/Expandability

When working with modules, it is so much easier and you’re so much more inclined to make reusable blocks of code.

Imagine every time a round in your game ended, you wanted a on-screen effect to play. Normally, you would have create code that would track whenever a round ended, then create the effect, then play it whenever the round ended.

Instead with re-usable modules, imagine if you already had a function that tracked when a round ended. Even better, what if it allowed you to attach a new function to play every time a round ended.
Now you’ve gotten rid of half the work. Any time you want something new to happen when the round ended, you just have to create the function, and attach it.

Obviously that’s a low-scale example, but that’s the type of stuff that you could do, thus making it easier to expand and update games over time.

Now finally, don’t fall into the trap of just using modules b/c they are the norm. Whether your game is client-sided or not doesn’t specifically invoke the use of a modular system, but it’s still recommended none the less.

But for a method of organizing the game, here’s the structure that I use:

  • Init modules and server running modules in ServerScriptService

  • General server functions and server utils in ServerStorage

  • Client init modules and client running modules in StarterPlayerScripts

  • General GUI module functions in StarterGUI

  • General utils (both client and server) in ReplicatedStorage

  • Server Init Script in ServerScriptService

  • Client Init Local Script in StarterPlayerScripts

  • Dedicated character local script + character module functions in StarterCharacterScripts

  • Local Script in ReplicatedFirst

3 Likes

Wait how would not using ModuleScripts affect performance?

1 Like

Having many different modules and functions inside of them technically do impact performance, but the impact is so negligible that it shouldn’t affect your decisions.

The main point is that modules are purely for organization and don’t give any performance boost.

2 Likes

Once they’re loaded they don’t affect the performance

1 Like

Calling a function inside of a module from a script is no different from calling a function normally. My point is that functions do technically affect performance, but its so negligible that it would appear the same on paper. Correct me if I’m wrong.

1 Like

I want to understand your way of thinking. Why do you think they affect performance?

1 Like

Scripts and LocalScripts run instantly, whereas module scripts run when required so to have more control over the load priority I believe it’s common practice to use a Single Script Architecture where you have initializer/start scripts in a Script/Local Script in the respective locations (ServerScriptService and StarterPlayerScripts) then each side has module scripts and you use a module loader to obviously run all the module scripts. I am quite new to that whole process but it was honestly quite quick to pick up and did absolute wonders for organization.

1 Like