Skip to main content

Require

Basic​

The require() function literally runs another Luau file and returns whatever that file returns and it does so each time you call it.

Game ver 0.15.0+

Builds >=0.15.0 will have return data from require cached - the script will be evaluated (run) only once.

Paths are resolved relative to the calling file:

  • require("foo") / require("./foo") - file in the same folder as the caller.
  • require("dir/foo") - file in a subfolder relative to the caller.
  • require("../foo"), require("../../foo") - walk up with .., as long as you stay inside mods/scripts/.

Aliases​

  • @root - refers to your script folder root
    Use this instead ../../../ chains when outside need a stable, depth-independent path inside your own script.
oxlib/math/vector.luau
local data = require("@root/helper/log") -- Your own script root (`/mods/scripts/oxlib/helper/log.luau`)
^ @root ^
  • @script - refers to /mods/scripts/
    Use this for cross-script import so you can require files from other scripts.
CustomScript/_init.luau
local vectorLib = require("@script/MyScript/lib/vector") -- `/mods/scripts/oxlib/math/vector.luau`
^ @script ^

Caveats​

  • require doesn't work with files outside mods/scripts/ directory.
    • This is part of the Sandbox for safety reasons.
  • No error is thrown if a file can't be required / is missing.

So both path traversal and missing files return nil