Requiring ModuleScripts parented inside each other

Attached is a .rbxl file of a bug I accidentally came across while scripting ModuleScript business. To cut to the chase, I’ll walk you through the process of encountering a bug.

game ReplicatedStorage Test Another

In ReplicatedStorage, there is a ModuleScript, Test, with another ModuleScript, Another, inside of Test. Test requires Another, with require(script.Another) with emphasis on the script variable. Upon doing so, however, I realize that the entire environment for Another is dumped into Test. The script variable in Test now refers to Another, and all variables in Another get dumped into Test. I proved this in the attached file.

The script variable changes regardless of if Test is being required in a server or local script. However, for the variables to actually transfer, you must require Test via command bar.

[code]require(game.ReplicatedStorage.Test)

The script variable refers to: Test
The script variable now refers to: Another
4[/code]

Attachments are broken

EDIT: Can’t repro. Did I do something wrong?
Place file: https://www.dropbox.com/s/sse9t4sxz4iuwlq/module%20bug.rbxl?dl=0

I reproed this in my game. I literally spent the last 2 hours removing every single environment dump to fix this.

Here’s what happens, it would appear…

SomeScript:
require(ModuleScriptA)

Inside of ModuleScriptA
print(script:GetFullName()) --> game…ModuleScriptA
require(ModuleScriptB)
print(script:GetFullName()) --> game…ModuleScriptB

Confirmed:

Game.ServerScriptService.Script (Script):

print("Script (1):",script:GetFullName())
require(Game.ServerScriptService.ModuleA)
print("Script (2):",script:GetFullName())

Game.ServerScriptService.ModuleA (ModuleScript):

print("ModuleA (1):",script:GetFullName())
require(Game.ServerScriptService.ModuleB)
print("ModuleA (2):",script:GetFullName())
return true

Game.ServerScriptService.ModuleB (ModuleScript):

print("ModuleB:",script:GetFullName())
return true

Expected results:

Script (1): ServerScriptService.Script
ModuleA (1): ServerScriptService.ModuleA
ModuleB: ServerScriptService.ModuleB
ModuleA (2): ServerScriptService.ModuleA
Script (2): ServerScriptService.Script

Actual results:

Script (1): ServerScriptService.Script
ModuleA (1): ServerScriptService.ModuleA
ModuleB: ServerScriptService.ModuleB
ModuleA (2): ServerScriptService.ModuleB <---
Script (2): ServerScriptService.Script

This is only in Studio ATM. Thanks for catching this. We’ll fix it as soon as we can in Studio, it won’t make it into player/server for sure.

This should be fixed now.

Made sure I was using the most up-to-date version of studio, and I am unable to require modules present in the game (not required from the site) through the command bar. Since the module is present in the game, there shouldn’t be any trust check issues requiring it.

There was a hiccup in the fix that went out two days ago. Last night we released a “fixed” fix :stuck_out_tongue: which should resolve this issue.