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

How do arguments work in regards to module functions?

Asked by 4 years ago

I’ve been looking into module scripts and I am getting the idea on how they work but when it comes to the arguments I don’t see how they work. Is it similar to a remote function’s arguments? Or does it work entirely different? A little help on this matter would be great.

No code for this question because this is for only a matter of understanding. For those ready to send me to the wiki I have already been there.

0
what about the arguments? royaltoe 5144 — 4y
0
it doesnt pass in a player like a remote function does and it executes the code fully before going on to the script you called it from royaltoe 5144 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

Once you get to understanding the workings of modules, they are a breeze there after.

First off. A module is code that can be called depending on where it is stored. If it is stored in a service that is replicated to the client e.g. workspace, replicatedstorage, replicatedfirst etc Then it can be required by the server and the client. If the module is stored in client only services such as playerscripts and guis then only the client can require them. And obviously this is the same for the server, with services like serverstorage and serverscriptservice. The server and client hold different data about the module which means that client-server communication is not possible through modules (this would be a security issue).

Now that we have that over with, we can ask ourselves how modules actually work. A module will only run it's sequential code once (when it is first required in the session), while this stops the sequential code from running multiple times, this does not mean that callable and stored data cannot be accessed. Data that is returned by the module can always be accessed by the script that required it.

Onto functions, functions are stored within a table when returned by a module. When these functions are accessed. By indexing the table returned. The function will receive the arguments that are entered, any data stored in the module or returned by the module is only accessible by the body that required it (a client or the server), this data can only be shared between bodies by the use of remotes (remoteevents/remotefunctions). Apart from that they are the same as any other function you may have used!

If you wish to know more about functions in module scripts, just comment and I will add onto my answer.

Ad

Answer this question