Debugging - tayjay/SCriPt GitHub Wiki

Debugging & Diagnostics

Two tools help you find problems in your scripts: a live VS Code debugger and per-script performance statistics.

VS Code Debugger

SCriPt can host MoonSharp's Visual Studio Code debugger, letting you set breakpoints, step through code, and inspect variables in your scripts while the server is running.

Enabling it

Set the DebugPort config option to a free port number (it is 0 — disabled — by default):

DebugPort: 41912

Only enable this on a development or otherwise trusted server. The debugger exposes your script source and lets a connected client pause script execution.

When the server starts you'll see a console line like:

[ScriptLoader] VS Code debug server listening on port 41912.

Connecting from VS Code

  1. Install the MoonSharp Debug extension for VS Code.
  2. Open the folder containing your scripts (LabAPI/SCriPt/Scripts).
  3. Attach to the debug server on the port you configured, following the extension's "attach" instructions.

What gets attached

Every loaded script is attached automatically:

  • Scripts in global/ and <port>/ attach when they load and detach when they unload.
  • The script execute console is attached too, so you can debug ad-hoc snippets.
  • The connection survives a script reload — scripts re-attach as they reload.

Set a breakpoint inside an event callback (for example onPlayerJoined) and trigger it by playing on the server; execution will pause on the line so you can inspect the args and your module's state.

Performance Statistics

If a script seems to be hurting server performance, you can have SCriPt measure it.

Enabling it

Set the config option (off by default, as it adds a small overhead):

EnablePerformanceStats: true

Reload (script reload) or restart so scripts pick up the setting.

Reading the stats

Use the command (requires the script.stats permission):

script stats <script_name>

<script_name> is the file name without .lua — the same name shown by script list. The command prints MoonSharp's performance log for that script (execution time, parsing/compilation, callback time, etc.), letting you compare scripts and spot the expensive one.

A typical workflow: enable the option, let a round play out, then run script stats MyScript to see where its time is going.

⚠️ **GitHub.com Fallback** ⚠️