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

Require Module script Children?

Okay so I've been looking into modulescripts and I get the use of them, how to use require and all that. My only question is can I call a function from a modulescript within the MainModule using require(assetid) ? If so how because when I do require it returns the error saying the modulescript I am looking for is nil. Sorry about not providing any sourcecode rn, about to head out and figured I'd ask this real quick and get back to it.

Pretty much what I have is: MainModule>FireMagics(ModuleScript inside MainModule) I tried testing by using a print cmd just to see if it was working, mod = require(assetid) mod.FireMagics.Print("Success") . And the Print function is just a basic print(msg).

When I use require, does it not retrieve the children of MainModule and if does how do I access them?

1 answer

✓ Accepted answer

I don't know if I got you right, but I'm assuming you want your MainModule to require a module parented to it.

So, first of all, make sure the module is a child of MainModule (like on this picture)

Now, if you want your MainModule to use that module, just use

require(script.ModuleScript)

or

require(script:WaitForChild("ModuleScript"))

in your MainModule.

(obviously replace ModuleScript with the name of your module)

1 comment

0

This worked perfectly, thank you! Would have never thought of it tbh.

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