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

How to run ModuleScript root function?

Asked by 4 years ago

Intended:

myModule = require(myModuleScript)

myModule()

I forgot how to accomplish. Every example references something similar to myModule.innerFunction() but I don't want that. I swear I've done it before

0
If your return value in 'myModuleScript' is a table, you could try using metatables and the __call metamethod. Using this, you can utilize a table with information AND you can call the table(https://developer.roblox.com/articles/Metatables in Metamethods section). saSlol2436 716 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You can just return a function???

— module
return function()
      print("nice")
end

—script
local module = require(module)
module() —> nice

and like saSlol said, you can utilise the __call metamethod to call the table.

Ad
Log in to vote
-1
Answered by 4 years ago

Nevermind my brain hurts. This is impossible as the require function simply inferences a dictionary of functions.

Answer this question