Setup:
- Script requires OuterModule
- OuterModule requires InnerModule
- InnerModule creates a new coroutine/event called Wrap
- OuterModule requires InnerModule
- Wrap requires OuterModule
Wrap yields forever. Wrap should wait for OuterModule to finish running.
This bug happens everytime. This bug happens on production/www.
Repro: RequireLoopWrapRepro.rbxl (13.2 KB)
Note that Required InnerModule(Wrap)->OuterModule
is never printed.
More info:
This seems to happen because Roblox assumes that if the to-be-required module’s coroutine status is normal
, then there must be a require loop and the coroutine should not be resumed. This assumption is incorrect in the above described scenario. In the above scenario, InnerModule still returns, so there is no require loop.
This assumption is usually correct because if InnerModule had required OuterModule directly, OuterModule’s status would be normal
and they would get stuck in a require loop.
It’s not correct to only check the coroutine’s status. In the above scenario in Wrap, OuterModule’s status is normal
, but Wrap is entirely capable of waiting for OuterModule to finish. In fact, if a wait
is added to the top of the Wrap
section, it does wait for OuterModule to finish. I think this is because the status of OuterModule is no longer normal
and now suspended
or dead
. This is shown in the following file: WORKAROUND.rbxl (13.2 KB)
Wrap can be a coroutine.wrap
ped function, a function triggered through a BindableEvent
, or anything else that creates a new coroutine that runs instantly.