RBXModuleLoader - An Advanced Module Loader

RBXModuleLoader

Version 1.0.0


Github Repo
Model Link

What is a Module Loader?

A “Module Loader” is something that’s used to load a bunch of modules, it is mainly used for the SSA (Single Script Architecture) which is for game organisation.

Why use this?

RBXModuleLoader is an advanced module loader with features such as debugging that can help you spot errors, view module loading times, loading order, etc.

It has a variety of settings, and includes features like changing the loading order, prioritising certain modules, and you can define custom filtering behaviour!


Example Code
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ModuleLoader = require(ReplicatedStorage.ModuleLoader)

local myModules = script.Parent.Services

-- Optionally changing the settings
ModuleLoader.ChangeSettings({
	DEBUG_MODE = true,
	WAIT_FOR_SERVER = true,
	LOADING_PRIORITIES = true,
})

-- Loading modules (all of the descendants),
-- returns a table of the required modules
local modules = ModuleLoader.LoadDescendants(myModules, function(module: ModuleScript)
	-- An optional predicate function / custom filtering function
	-- Must return true or false
	
	-- This means it will only load modules that have "Service" in their name
	if module.Name:lower():match("service") then
		return true
	end
	
	return false
end)

-- Start / Init
ModuleLoader.RunModules(modules, "Init")
ModuleLoader.RunModules(modules, "Start")
Functions
Load - Loads the given modules that are in a table, optional predicate function
LoadChildren - Loads all the children of the parent passed, optional predicate function
LoadDescendants - Loads all the descendants of the parent passed, optional predicate function
RunModules - Runs the method passed on the loaded modules
GetModule - Returns the loaded module of the name passed
IsServerLoaded - Returns if the server has loaded (only used by the server)
IsClientLoaded - Returns if the client has loaded (only used by the client)
ChangeSettings - Change the settings of the module loader

Any Feedback is Appreciated!

by @I_p2z

2 Likes

I know I’m going to sound incredibly stupid asking this question. But I’ll ask anyway because I need a bit more information for my rookie dev brain

Could you give me more details about this ModuleLoader capabilities and why should I consider using this?

1 Like

This ModuleLoader just has more features than a plain module loader which just loads all your modules. For example, you can edit the loading order of your modules if you want a module to start before another module for whatever reason.

It also has other features as well like debugging which can help you see which modules are taking longer so you could optimize those modules.

There’s other features like predicates (custom filtering functions) but i’m not gonna go over all of them.