Simple Module Loader Base

Hello, I’d like to share this simple module base I made in Roblox a while ago:
Roblox_ModulesBase.rbxm (2.4 KB)

This is a simple module loader meant to initialize your core systems automatically and have a centered place with said modules


Setup

  • Move the ServerStorage folder to ServerStorage, ungroup
  • Move the ReplicatedStorage folder to ReplicatedStorage, ungroup

Structure

  • ReplicatedStorage.Modules contains both Client and Common modules
    image
  • Server modules are located in ServerStorage
    image

You can change each module root inside of ModuleRoots

Common modules are loaded on both client and server side, the others are only loaded on the side it’s meant for

You can then get all the modules by requiring ModuleLoader, which will return a table

type Main = {
	Root: Folder,

	Client: Types.Client,
	Server: Types.Server,
	Common: Types.Common,
}

When you make a new module, you should add it to ModuleTypes, this is an empty ModuleScript which is only meant for typing

export type ExampleCommon = {
	MyModule: typeof(require(root['common'].MyModule)),
	MyFolder: {
	  NestedModule: typeof(require(root['common'].MyFolder.NestedModule)),
	},
}

Hope you like it!

5 Likes

looks easy to use, ill give this a try!

@A_Mp5 @Yarik_superpro

2 Likes

I think the name speaks for itself, doesn’t it?
It’s not rocket science, lil bro.
Module loaders are fundamentally all bad, no exceptions.

2 Likes

but why are module loaders bad…

qwertyuiop

Learn how Luau VM pushes the stack and what a register is.
Question answered.

1 Like

They’re pointless
If you want stuff to load instantly, put it into a single script

3 Likes

:waving_hand::waving_hand::waving_hand::waving_hand::waving_hand::waving_hand::waving_hand:HAii so I saw this resource and I saw how great it was… like actual transcendence wrapped in a ModuleScript. I don’t say this lightly — it looked less like a utility and more like the kind of architectural breakthrough that makes entire IBM engineering departments stare out a window and question their careers. It felt like the generational leap from “stone tablet chiseling” to “quantum-accelerated butter-smooth computation.”

The moment I read it, I genuinely thought:
“Oh. This is it. This is the framework that will lift my game into a higher dimension. Because if there’s one thing Luau is universally praised for, it’s how flawlessly and effortlessly OOP scales, right?”

I was certain it would bless every subsystem, every coroutine, every remote event, every poor line of code crying in ServerScriptService. It looked like the kind of architecture that doesn’t just improve performance — it enlightens it.

But!

Nooo ;~; my game began running really slow :cry::cry: and my paws hurt from trying to debug it and I am genuinely asking for help because I think I did something horrific with this super sophisticated module-loader aaaa

So context: I used to have one (1) unholy monolithic script in ServerScriptService that did everything like a bible page taped to a lawnmower. It was ugly, but it was fast — like a consistent 60 fps on my toaster laptop. The most “OOP” it had was local function butLongerName() and I was like “haha I’m such a script kiddie meow :paw_prints:”

Then I saw your lovely high-class engine-framework-module-base-thing and my smol brain was like “omg this is so production, so enterprisey, so CI/CD-coded-in-cologne,” and I thought “if I just refactor everything into this design my game will instantly become a sensation and adopt an ISO standard.”

I spent three days straight converting the entire monolith into classes and modules and submodules and ModuleRoots and local Types = require(...) and Common/Client/Server folders. I kept saying things like “wow this scales so well” while my playtest fps went from 60 → 40 → 28 → hahaha what is a frame :sob:

Here is the repro steps (I’m sorry it’s long, my hands are shaking):

open roblox studio and take my once-fast script and split it into like 38 different Modules with “BaseController” and “Service” and “Manager” in the name then install this fancy module loader from the thread and configure ModuleRoots and put common stuff everywhere so both client and server can feel included then add a types module that has no code and just requires the other modules “for typing” but now everything is double-required and then remove all my dumb but fast tables and replace them with classes and metamethods and :New() and :Init() and “dependency injection” I found C&P on the internet and then I press publish-to-world while a mid-sized CCU spike is happening because I thought “can’t be worse right :face_savoring_food:” and after I published the game mid-CCU-spike EVERYONE STARTED LEAVING AND THEY KEPT LEAVING AND MY CAT ATTACKED ME and now my brain is screaming and I don’t know how to undo :sob::sob::sob::sob::sob:

expected result:
my game becomes elegant and modern, the scripts put on tiny suits and ties, the objects gain “weapons-grade abstraction,” and the only thing wagging is my tail because my code is so perfect

actual result:
fps: went from 60 to “is this a slideshow”
ccu: tanked so hard I thought the analytics page bugged
gc: stomping through my memory like Godzilla in Tokyo
my parents: somehow fighting about “financial responsibility” the same night I pushed the change
my car: started leaving random little oil puddles the day after (screenshot of oil-circle mindmap attached in my soul)
my AC: chose to stop cooling exactly when the servers started cooking
my cat: actually bit me and then ate my bird’s seed and then my bird, and now I have a very full cat and a very empty cage

I tracked a bunch of metrics because I wanted to be “furry-scientific” about it and now I am even more scared because they all look like this :crying_cat:

(see all the attached graphs my CPU collected while sobbing, I don’t understand half of them but they feel very important and most of them go down except the bad ones that go up)

I honestly don’t know if I misused the module loader or if my brain just isn’t meant for “service locator patterns,” but right now every time I type :Init() I feel like I’m reducing another relationship stability index by 0.5 and increasing cat aggression by 2 and I need advice on how to:

  1. make my code not be a single ancient mega script
  2. without turning it into a six-layer OOP onion that makes the VM cross half the map just to find a function that used to be a local upvalue

Nooo ;~; if anyone can tell me how to get the performance back without restarting my entire life all the way back at “one dumb script fast” I will send you a virtual headpats coupon and a cat pic (once he stops trying to murder me for the OOP sins I’ve committed)

No this causes viruses please stopo

What is a Luau? I know what I register is and im not allowed to touch it because it has money inside

WHAT

:cry:idid too o

Thanks for the help everyone

7 Likes


tuff

2 Likes

Oh, this SCP Foundation is doing [REDACTED] to text.
Won’t even leave devforum alone.

1 Like

WHAT!?
NO! IT CAN’T BE
IT’S LITERALLY SO PRODUCTION-READY AND SO ENTERPRISE SYNERGY™:

  • Gold-Plated Industry Standard®
  • Cognitive Vectorized Metric Pipeline™
  • Enterprise-Grade Robustness Matrix©
  • Quantum-Ready API Alignment®
  • Scalable Synergistic Paradigm Shift™
  • ISO-9001 Object-Oriented Spiritual Framework®

SEE!? IT’S JUST YOUR COMPUTER LAGGING.

1 Like

If youre looking for holy transcendence use Jecs +100000000 scalability and performance you just have to know how to use it

Theres no fixed structure like mvc or whatever so you can do whatever tf u want with queries

This Post Was Brought To You By The JEcs Transcendence Society (JETS) :trade_mark:

Alr module loaders are bad. But what if I just initialize the modules I need in a Script/LocalScript specifically for module initialization? Is that good, or is there anything wrong with doing that?

I want to know cuz I’m using some modules that really need to be “loaded” when server/client is started

If you use it for sharing player data like datastore values used across multiple scripts, it’s ok.
But when you use it as a glorified yielding mechanism, that’s when it’s a misuse.
TL; DR: Sharing values is ok; sharing functions is not.