Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to run ModuleScript root function?

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

1 comment

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).

2 answers

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.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.