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

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

Asked by
Kurieita 125
7 years ago

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

0
require turns the script into a function which you can then call it. it looks like you never called it NewVoids 97 — 7y
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) brianush1 235 — 7y
0
:/ ^ Kurieita 125 — 7y

1 answer

Log in to vote
0
Answered by
brianush1 235 Moderation Voter
7 years ago

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.

Ad

Answer this question