If i want require in my module any modules then
it just doesn’t load in other scripts.
with
without
Error when you try to require modules in a loop.
Check your modules!
ex
Module A
require(ModuleB)
Module B
require(ModuleA)
In additional, you can require module with new task
local ModuleA
task.defer(function()
ModuleA = require(...)
end)
You’ve created an infinite loop by having 2 module scripts require each other, like 2odin66’s example.
The local ModuleA task.defer(function() ModuleA = require(...)end)
is essentially a way to “delay the module requirement”, or in other words “defer requiring a module until after the current script execution cycle” which could solve your problem. Could read more on that here for a more proper explanation, rather than my half baked one: task | Documentation - Roblox Creator Hub
This is a recursion issue and can happen quite easily when multiple modules rely on each other. The way I solve it most of the time is that I reference a module as another module property, so I don’t have to use require multiple times when associations are found. Basically something like:
Serializer.Base64 = require(...) --path to base 64
where Serializer
is also a module. That way if I happen to need the serializer module and also the base64 module I don’t need to require base64 again I just call Serializer.Base64
.
Another way to tackle the issue is to create some sort of graph with arrows of which module requires what. That way you can find cycles by simply looking at the graph. After locating such cycles you can get rid of them with tricks like the one mentioned above, but you should always implement OOP practices along with it. Try to make your code look logical and easy to understand.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.