How many scripts should I use?

Should I use multiple server scripts, or 1 with modules? If I did make multiple server scripts how would I communicate information between them?

2 Likes

By using StringValue, BoolValue, etc.

1 Like

BindableEvent and BindableFunction are good ways to communicate through different live script instances, and with modules you can provide interfaces via the functions you return from them.

8 Likes

It is personal preference. Some games use one server script(a god script) and run all their modules from that script. Other games use multiple server scripts and hook up various modules to them. Then the scrips communicate to each other via BindableFunctions and BindableEvents. You may want to read over this thread as it is similar to what you are asking: How do I avoid a "god script" in a modular structure? Or is it even worth pursuing a fully-modular hierarchy?

The only disadvantages I can think of with using one Server Script is that you need to make sure you make good use of pcall’s to handle errors. Also you need to be conscious when you use loops as they could yeild the whole of the server meaning that you need to make good use of coroutines.

1 Like

My personal preference is to make a ModuleScript with all my functions that I might need to access from different scripts. This way you can call those functions without using events. Another thing I love about ModuleScripts is they can be used by both the Client and the Server. If the Client runs a function in a ModuleScript, it will act like a function ran in a Local Script and vice versa. This can help a lot if you’re repeating code in multiple scripts.
I personally don’t like using one giant script as it becomes difficult to find what I’m looking for quickly.

In my game theres currently 17620 lines of code. I use a single local script and script architecture, the client one makes up about 165 lines and the server about 350. The rest of the lines are used by 166 module scripts. I personally find this setup pretty good and manageable. In any case i suggest that you use many(modules, scripts, local scripts or whatever), cant recall what this paradigm was called.

Also be careful about using a module for both the serverside and clientside. As this would mean that the client could access it which means that it can be taken by an exploiter.

You could use modules as a means of communication between scripts and local scripts seperatly.

It’s not really a “should I” situation. It’s more of what you want to do. Some programmers like to have one “main script” or multiple ones. Although, to keep everything neat and tidy I would recommend having minimal scripts, that is just my way of setting up projects or programming.

1 Like

For all my games, I have one server script(serverscriptservice) and one client script(starterplayerscripts). I use generic handlers(handlers that can be manipulated based on the data you pass to it). I use remotes to communicate with them. I found that this seems to be the easiest method for me.

If you have a bunch of scripts, the game gets rather complicated and harder to maintain. If you’re neat and organized, you have a higher chance of knowing where your code is. Over-complication doesn’t mean better which I feel is a misconception.

3 Likes