Hey, how can I call a whole module script? If I have a module script with 2 functions that print 1 word each. I can easily request the module script in another script and call one of the two functions, and the word of the associated function will be printed. But how can I call the entire module so that every function in the module will be performed? So that both words will be Printed
Quick and dirty explination:
Step 1: Create your modulescript
Step 2: Open your localscript or script, and require it
local myModule = require(game.ReplicatedStorage.MyModuleScript)
Long explination:
Your modulescript will return a table that you can use as an API
Your module script should look like this
local module = {}
return module
You can add values to your modulescript to be used for later, this also includes functions too
here is an example:
local module = {}
module.someValue = "Hello World from the ModuleScript"
return module
In your script you can access these values like so
local myModule = require(game.ReplicatedStorage.MyModuleScript)
print(myModule.someValue)
Happy scripting!
It isn’t possible to call a Modulescript to run every function without making another function that calls every function inside it. Example, in a ModuleScript I did this
local module = {}
function module.Print1()
print("Print1")
end
function module.Print2()
print("Print2")
end
function module.callAll()
module.Print1()
module.Print2()
end
return module
And in a regular script I did this
local module = require(game.ServerStorage.ModuleScript)
module.callAll()
Result was this
Not sure if this is what you meant, but in short, there’s no way to call all functions in a ModuleScript without making your own function to do that, meaning you’ll have to do a bit of work having to make the function call the other functions, which can be a bit of a hassle to do, there may be a way to make it so if the thing in the module table is a function it loops through it so you don’t have to write the function call yourself
Update: I found a way you can do the callAll function without having to call the functions yourself
function module.callAll()
for _,func in pairs(module) do
if typeof(func) == "function" and func ~= module.callAll then
func()
end
end
end
If what it is on currently is a function and the function is not the callAll function, run it.
i mean you could just set the environment to the same environment as the modulescript, and use its functions that way, or just create global variables to use from it(which is not recommended)
The thing is that @OPs original question was how could he make it so that all the functions in his module can be called at once, so he doesn’t have to call t hem one by one. To quote them,