Skip to main content
Util scripts let you organize your code into small, focused modules that can be reused across multiple scripts. They’re ideal for math helpers, geometry utilities, color functions, or any logic that should be broken out into its own script.

Creating a Util Script

Create a new script and select Util as the type.
--- Example helper function.
local function add(a: number, b: number): MyUtil
  return a + b,
end

-- Return the functions you'd like to use in another script
return {
  add = add,
}

Usage:
local MyUtil = require("MyUtil")

local result = MyUtil.add(2, 3)
print(result) -- 5

Utils with Custom Types

Custom types defined in your Util scripts will automatically be accessible in the parent script.
--- Defines the return type for this util.
--- The type is automatically available when you require the script.
export type AdditionResult = {
  exampleValue: number,
  someString: string
}

--- Example helper function.
local function add(a: number, b: number): AdditionResult
  return {
    exampleValue = a + b,
    someString = "4 out of 5 dentists recommend Rive"
  }
end

return {
  add = add,
}

Usage:
-- With type annotation
local result: AdditionResult = MyUtil.add(2, 3)