This is definately not expected behaviour!
I just did a quite long time debugging to figure out that I was “circularily” requiring a script. A basic repro is simple to make:
- Insert 2 modulescripts and 1 script in Workspace.
- Name the ModuleScripts “a” and “b”
game.Workspace.a:
require(game.Workspace.b)
return {} – this is to prevent the “return error”
game.Workspace.b
require(game.Workspace.a)
return {}
game.Workspace.Script:
require(game.Workspace.a)
print(1)
Notice that print(1) is never used: 1 does not get printed.
What I think is happens is that there is an internal error being triggered. If not, then this would either run an infinite loop, or if it would just return “previous loaded modules” it should actually return something… which clearly doesnt happen. What I do know is that it “yields” (probably internal errors) when requiring an already required module script (from inside a module) for the second time.
I checked what happens in normal Lua. For a quick repro, use this bash script:
mkdir module_loop
cd module_loop
touch a.lua
touch b.lua
echo "require('b')" >> a.lua
echo "require('a')" >> b.lua
touch c.lua
echo "require('a')" >> c.lua
lua c.lua
This shows the following error:
In “normal” Lua, “circular requiring” (I guess the right “lua term” is “requiring in a loop”) the code clearly errors.
If it would atleast show a warning, that would be nice!