Play Strawberry Docs
Scripts

Module scripts

Export functions that your other scripts on the same server call, with the limits and the error codes a call can answer.

Export a function and call it

A module script exports typed functions that your other scripts on the same server call, like a ModuleScript and require in Roblox. The call goes through the server, and each script keeps its own permissions.

  1. Declare the functions once with strawberry_plugin_api::module_api!. Both scripts use the same declaration.
  2. In the module script, give each function its body in Plugin::new: the server reads the list once, when it loads the module.
  3. In the calling script, name the module in dependencies in its metadata, then call the typed function.
rust
strawberry_plugin_api::module_api! {
    /// The arena of my game.
    pub mod arena = "my-arena" {
        /// Starts a round for these players; answers the round's number.
        fn start_round(players: Vec<String>, seconds: u32) -> u32;
    }
}

// In the module script "my-arena", in `Plugin::new`:
arena::export::start_round(|players, seconds| { /* start the round */ 1 });

// In a script that names "my-arena" in its `dependencies`:
let round = arena::start_round(vec!["Alex".into()], 60)?;

Arguments and results are copied as JSON, so use types that serde can encode.

Limits

  • A call must answer within 2 seconds.
  • Its arguments and its result are at most 1 MiB each.
  • While a module answers, it cannot call another module (depth 1) or send a script message.
  • Use module calls for game logic, never in a per-block or per-tick loop.

When a call does not run

The call returns a ModuleCallError, and its code() says why:

  • not-found: no module of that name runs on this server. It is missing, was refused or was unloaded.
  • reloading: the module is loading or reloading. Try again in a moment.
  • not-declared: your script did not name the module in its dependencies.
  • not-same-owner: the module belongs to another owner. Only your own scripts on the same server call each other.
  • not-exported: the module does not export that function.
  • nested: a module call from inside a module call, or a script calling itself.
  • timed-out: the module did not answer within 2 seconds.
  • failed: the module's function failed (it returned an error or stopped), or the arguments or the result are over 1 MiB.
  • encode or decode: your arguments could not be encoded, or the answer is not of the declared type.

On this page