✓ Accepted answer
There are two ways of require()ing a Module script.
The first one is by passing the module script as argument:
require(game.ServerScriptService.MyModuleScript)
The second is by passing it the assetID of a Module script that has been published to Roblox as argument: require(3858375)
A module script must return at least one value. The type of this value and its usage is up to the user, however. require returns that value, which can then be used by the require()ing script. Usually you would return a table, formatted as a dictionnary, which contains functions and optionally variables.
For example:
local module = {}
module.a = 20
module.foo = function()
print("Hello from 'bar'!")
end
function module.bar()
print("Hello from 'bar '!")
end
return module
And then from a normal script:
local myMod = require(game.ServerScriptService.MyModule)
myMod.foo()
myMod.bar()
print(myMod.a)
Since you are able to return anything you want from a module script, you could also return a function, which is what allows for crazy code such as:
require(3858375)()
So the require(475858285)(script) part you mentioned is really just sending a reference to the current script as argument to the function returned by require.
Hope that helps. If it did, please make sure to mark my answer as accepted and optionally upvote, it helps us both. :)
If you have any further questions, feel free to ask.
2 comments
Yes and no, I understand about the (script) part now, but how would I call a specific function from the modular script if I was requiring it from online? The script has 2 functions and I only want to call one of them.
Well, I showed how to call a module function from the require()'ing script in my example. It depends on the module script, really. But I'd assume the function returned by your module script, when called, returns a table of functions. Try this, for example: "local myMod = require(475858285)(script) myMod.func()".