Strategies For Indexing / Finding Scripts in the Game Structure / Directory

1. The Situation:

I’m working on a big game that has many scripts, using studio script sync^. To make life even more complicated, the game/experience features multiple places. There is overlap in the scripts between these two places, but it is not total, i.e.

Place 1 requires script packages A, B;
Place 2 requires script packages B, C;

Thus, to make maintenance/development of these packages not a nightmare, I have structured my game directories similarly to:

ReplicatedStorage.A.Scripts.BlaBla.ModuleScriptXYZ
ReplicatedStorage.B.Scripts.BlaBla.ModuleScriptBNM

ServerScriptService.A.BlaBla.ModuleScriptIOP
ServerScriptService.B.BlaBla.ModuleScriptTYU

“Place 2” in the above example would then have “root folders” B and C, instead of A and B.

2. The Issue:

This then means that in all of my scripts, I need to explicitly find each module script I want to reference, i.e. fully qualify my module scripts:


-- Generic script:

local ModuleScriptXYZ = require(game.ReplicatedStorage.A.Scripts.BlaBla.ModuleScriptXYZ)
-- ... and so on, for MANY modules...

This becomes extremely unwieldy, especially when I needed to move literally every script in my game to conform with the A/B/C foldering style so that I can script sync more intelligently.
You can imagine how painful that was - thankfully vibe coding tools made this much easier (but still miserable).

(Understand that this game was originally written way before script sync was a thing, and rojo was still a pretty fledgling tech).

3. The Solutions I’ve Tried:

To get around this, I built a module script that, upon first load, reads through the whole game directory and caches a dictionary that maps module/script names to their instances.

Consumers can then find scripts via

ScriptRegistry.GetModuleScript("ModuleScriptXYZ")

and, in runtime, it works! Lua magic, yay!

The problem here, though, is that this breaks Intellisense! Since static analysis can return in the best case a generic “ModuleScript” type (as the exact module types are determined at runtime), I lose any information on what methods the module contains, and indeed can’t “find definition” of methods that I essentially am guessing exist. This is not ideal, and frankly I am now leaning towards going back to fully qualified declarations (i.e. ReplicatedStorage.A.Scripts.BlaBla…)

In OOP-land, there would be several strategies to deal with this scenario (Dependency Injection my beloved, or just type-casting to the expected module types), but I can’t seem to figure out any Luau ways to accomplish this (as, of course, modules are not true class types but rather just spicy tables).

4. The question:

How are y’all handling this problem?

Are you using fully qualified declarations, or some other strategy?

I’ve tried googling, searching the dev forum, chatGPT’ing, Claude’ing, and I’m kind of at wit’s end here.

I guess a last resort would be to, like, fully qualify all the scripts by hand in my “Script registry” module and then have a getter for each module, but I suspect that also wouldn’t work too well, and would obviously suck to maintain.

Though to be honest, maybe that would still be an improvement.

Thanks for reading!

I just put all my scripts in one folder and make it a package. For example a “Shared” folder. Turn it into a package and just use it in multiple places. And I do this for every other folder, such as a “ServerScript” folder, or “Client”. I just find scripts by doing

local utils = require(game.ReplicatedStorage.Shared.Utils)

It just seems like you might be over complicating it a bit. Is there a reason you need A, B, and C folders? I never had any issues with a single folder approach (Shared, Server, Client), with syncing and packages too.

Succinctly, it arose as I wanted to maintain the packages separately, since each place uses different packages; I didn’t want scripts specific to place A that do nothing in place B to exist in that place, and having them all in a package together meant they would.

What you’re suggesting in your Require is basically exactly what I currently have, and want to avoid;

it means that moving a script breaks the asset references to it in each script, which is brittle and can hide bugs until those scripts end up indexing null or whatever in runtime.

Re: sync issues - my problem was that I didn’t have the scripts separated at first, meaning I had to move them all (and thus break ALL of my script references…).

Before doing this, I was having issues with duplicate names/directories (with script sync).

With Rojo, I was having issues communicating changes to the shared scripts between places.