"Requested module was required recursively"

Basically, I use functions from modulescript1 in modulescript2, and use functions from from modulescript2 in modulescript1.

My issue is fixed if:
I can pull out variables from a localscript and use them in my modulescript, my issue is fixed
if I can somehow use functions from modulescript1, in modulescript2, and use functions from from modulescript2, in modulescript1

your two modules require each other on require, just require it right before using it.
ex:

local module = {}
local otherModule = require(...) -- this module requires this module on require, which makes it recurse

module.doSomething = function()
    otherModule.doOther()
end

do this instead

local module = {}

module.doSomething = function()
    local otherModule = require(...) -- this module requires this module on require, which makes it recurse
    otherModule.doOther()
end

This works!

But, wouldn’t that create some delays and potentially some lag? I’d like to “load in” the modules before the function is run, if that’s the case :D

you can make init function which requires needed modules and just call when you start the module

May you elaborate? I’ve never heard of this

local module = {}
local secondModule 

module.init = function()
 secondModule = require(...)
end

module.doSomething = function()
   -- can check if secondModule is not nil
    secondModule.doSomething()
end


--// main
local module = require(firstModule)
module.init()
module.doSomething()
1 Like

its just to require module NOT on each require but also not on each function call that requires to use the functions of the second module

init stands for initialize btw

This also worked, thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.