Introducing Require-by-String

Hello everyone, we have a new update regarding require-by-string!

We’ve heard your feedback about requiring script children and are happy to announce that we have now enabled the @self alias platform-wide. This new alias allows you to directly require children of the current script as follows:

-- without require-by-string
require(script.Child)

-- old way
require("./{CurrentScriptName}/Child")

-- new way
require("@self/Child")

Based on other feedback, we’ve also decided to remove the special treatment of Init ModuleScripts. Previously, any instance could be require’d by string if it had a child ModuleScript named Init or init. This behavior was originally implemented to mimic the treatment of init.luau files on the filesystem. In a conventional filesystem context, files cannot have children, so a code module with children must be represented as a folder containing an init.luau file. In Roblox, however, this issue is not present: code modules are represented as ModuleScripts, which can have children.

Rather than creating a Folder with a child Init ModuleScript, we recommend simply converting the Folder to a ModuleScript itself and nesting children under it—the new @self alias makes it simple for the top-level ModuleScript to access its children. To make this simpler, Roblox Studio now throws a runtime error with migration instructions when attempting to implicitly require an Init ModuleScript.

For more information, please refer to our updated documentation!

11 Likes