Debugging - tayjay/SCriPt GitHub Wiki
Two tools help you find problems in your scripts: a live VS Code debugger and per-script performance statistics.
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.
Set the DebugPort config option to a free port number (it is 0 — disabled — by default):
DebugPort: 41912Only 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.
- Install the MoonSharp Debug extension for VS Code.
- Open the folder containing your scripts (
LabAPI/SCriPt/Scripts). - Attach to the debug server on the port you configured, following the extension's "attach" instructions.
Every loaded script is attached automatically:
- Scripts in
global/and<port>/attach when they load and detach when they unload. - The
script executeconsole 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.
If a script seems to be hurting server performance, you can have SCriPt measure it.
Set the config option (off by default, as it adds a small overhead):
EnablePerformanceStats: trueReload (script reload) or restart so scripts pick up the setting.
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.