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

Why can't a module script require a module script->vice versa?

Hello fellow scripters, been a while. Ignore the title, it make no sense. I know. Anyway, what I want to do is simple. According to my knowledge when you require a module script, what ever the module script return get stored into a variable and only get loaded up one time. So if you try to require the same module, what ever it returned the first time will get returned the second time. Correct?

Well, if this being the case.Why can't I do this? It act as an infinity recursive loop.

Module A

local ModuleB = require(ModuleB)

ModuleB

local ModuleA = require(ModuleA)

Server

local ModuleA = require(ModuleA)

This isn't exactly how my code is, but it gives you the basic idea. Why can't I require a module script like this?

-Kurieita

3 comments

0

require turns the script into a function which you can then call it. it looks like you never called it

0

@NewVoids That's wrong. require "returns what the ModuleScript returned" (http://wiki.roblox.com/index.php?title=Global_namespace/Functions_specific_to_ROBLOX#require)

0

:/ ^

1 answer

This is happening because you're requiring the first module script, which requires the second. Afterwards, the second module script requires the first one, before it has finished loading. A module script can't be cached if it hasn't finished loading, therefore you can't require a module script to cause a recursion.

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