Require module by keyword

Currently to require a module, you need to do require(modulePath), eg require(game:GetService("ReplicatedStorage"):WaitForChild("MyModule")). Typing that at the top of every script is a pain, looks messy and nobody likes it

Adding a new property to ModuleScripts, ModuleScript.ReferenceBy could help solve this. Calling require() and passing a string would find a ModuleScript with the same ReferenceBy property and require it. If a module doesn’t exist with that reference, it could either return nil or wait for a module to exist with that reference (this would be the case on the client before the module gets replicated)

require("MyModule") is much better than require(game:GetService("ReplicatedStorage"):WaitForChild("MyModule"))

15 Likes

The issue I would see with this is if more than one module has the same ReferenceBy property. There would be ambiguity. It is also more readable to type

Than just "MyModule". The former actually tells me where it is.

1 Like