Requiring ModuleScript using different path leads to script be called twice

Hi everyone,

I recently encountered an issue where my ModuleScript seems to be executed twice, leading to multiple instances of the same module in my game. Here’s what I noticed:

When I require the ModuleScript using different paths, like so:

lua

local test_controller = require(script["test.controller"])

and

local test_controller = require(StarterPlayerScripts["test.controller"])

The test.controller.luau script gets called twice, resulting in two different instances of test_controller.

My question is: Is this intended behavior in Roblox, or is it a bug? I would expect that a ModuleScript would only be executed once per environment, but it seems like requiring it from different paths treats them as separate instances.

I’d appreciate any insights or official clarification on whether this behavior is by design.

Thanks!

Assuming this is in a client context, it’s not a bug. Contents inside StarterPlayerScripts will get cloned onto the player’s PlayerScripts upon joining, so they have a clone of the module. To get the same module from a different client script, reference the cloned module instead.

1 Like