Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Should I use a module script or a remote event/function?

Asked by 5 years ago

I recently read that module scripts work with filtering enabled. Why would I ever use a remote event/function again when I have the option of using a module script instead. Excuse my inexperience. I have only been scripting for a couple of months and I don't totally understand the different options. Please help me understand. Thanks!

1 answer

Log in to vote
0
Answered by 5 years ago

I think you're confusing the usage of module scripts and remote events/functions. Yes module scripts work with FilteringEnabled, but it still serves a different purpose than a remote event/function.

Module Scripts

The main purpose for module scripts is to access code or variables that multiple scripts need access to.

An example being a function that iterates, or loops, through a table and finds a specific value. Writing this function in multiple scripts would be redundant and that is where module scripts play in.

Another example being data storage for assets. If you were storing data values for all the weapons in your game such as, "Bullet Damage", "Bullet Speed", "Recoil", etc, you could use a module to store this and have a the scripts require() the data needed.

This is far better than copying a large table to multiple scripts and would lack the adaptability to add weapons since there would be multiple locations that need the same data.

Remote Events/Functions

Remote Events and Functions are used to communicate between the Server and Client, since with FilteringEnabled, most changed made on the Client do not replicate to the Server.

Remote Events do not yield and do not return a value, while Remote Functions do yield and do return a value.

An example use for a Remote Event is simply notifying the Server that a player has toggled their AFK status.

An example for a Remote Function would be getting the game timer from the Server.

Overview

Basically, module scripts are used to have code in one place that multiple scripts need. Remote events/functions should be used when you need to communicate between the Client and Server.

Hope this helps!

0
Thank you! User#21908 42 — 5y
Ad

Answer this question