RequirePlus: Require ModuleScripts without writing full paths

This is a simple module I made to require ModuleScripts without writing the path to them in the require function every time.

The module has two functions and an initialized event.

To initialize the module simply require it normally and call :init(). The init() function accepts one parameter which is an array of directories where ModuleScripts will be looked up, you can also make it scan the whole game by not passing any parameter to the init() function.

Once initialized you will be able to require each registered ModuleScript by passing its name as parameter in the requirePlus() function.

For example say that you have a module named “MyModule” and you want to require it, you can use the code below.

local requirePlus = require("PathToRequirePlus")

requirePlus.initialized:Connect(function()
    local myModule = requirePlus("MyModule")
end)

requirePlus:init({game.ServerStorage}) --This will only register modules that are located in ServerStorage

If you want to scan the whole game simply don’t pass any parameter to init()

local requirePlus = require("PathToRequirePlus")

requirePlus.initialized:Connect(function()
    local myModule = requirePlus("MyModule")
end)

requirePlus:init() --This will scan the whole game.

It is suggested to specify the directories where modules are located as this will provide a faster operation, moreover scanning the whole game may also include ModuleScripts located in a player instance.

This is a quick module I made, mostly to speed up the work, if you are looking for better speed performance this probably won’t fit your needs

RequirePlus

3 Likes

I would love to see official benchmarks to see the performance difference between roblox’s require function and your custom requirePlus function.

This just feels like it’d bloat a workflow especially considering how the syntax of require works perfectly for all use-cases already.

I believe if you provided some actual real-world example for some of the uses of this module it may be easier to understand

1 Like

Sorry i may have explained this badly, but the point of this is to not write full paths to a module

I believe that he sees that, but he is asking how it might affect his game on it’s performance. As performance is probably more important then a quick workflow, at least in my opinion.

About the module, I think it is definitely cool, but the process of using it should be shortened a little so that we can more easily use it.

1 Like

Your right, it is easier to not right entire paths to a module. But I feel like your module just makes it harder to require. You could be writing one line of code, but instead with this you have to write 5 lines of code. So the only benefit this has is writing the name of your module?

You could just do:

local RequirePlus = require(script.Parent)

RequirePlus:Require("ReplicatedStorage", "MyModule")

Also, please, do not use BindableEvents. Use GoodSignal.

1 Like