Module Scripts or Remote Functions

Hey everyone,

I’m currently in the process of optimizing and recoding a lot of aspects of my game (spring cleaning ya know).

I’ve been doing some research both on DevForum and the world wide web on whether it’s better to have a Module Script or a host of Remote Functions. The answers I was finding weren’t really the most clear as to when specifically one is better than the other.

Anyways, I was hoping someone (or plenty of people) could give me some specific instances (maybe even in a list format since I’m not the smartest) where you would definitely want to use a Module Script over Remote Functions or Remote Functions over Module Scripts.

Or if you’re just just an ardent believer in Remote Events being the god of them all, please let me know that too :slight_smile:

Thanks in advance everyone!

The two aren’t really in the same category so they are not interchangeable. Module scripts are for organizing code. Remote events and functions are for communication between the server and players.

4 Likes

a remote event should be used when something needs to be changed server-side. I generally just use module scripts for everything else.

Modules are irrelevant here as Blokav points out, but RemoteFunctions should be avoided in general. You can’t invoke ot the client without writing a wrapper, because there’s no guarantee it will ever return. Invocations to the server are best replaced by RemoteEvents, an event-based approach is better than yielding.

I get what you mean (generally speaking), but can you be more specific? Organizing what kinds of code? To be used by what for what? I know that it obviously depends on the context, but organizing code is a little vague.

Anything and everything. There are a bunch of threads related to the use of modules to accomplish certain systems, paradigms, architectures or whatever you’d like to do. Here are some examples of key terms you may come across (and want to look up):

  • Framework
  • Single responsibility principle
  • Single script architecture
  • Object-oriented programming (often done via ModuleScripts)
  • Lazy loading and eager loading

Here are a couple of threads that I know delve into the code organisation situation and also encourage the use of ModuleScripts heavily where possible such that you need little to only one script which serves as the entry point of code for the machine:

Among countless others.

5 Likes