Skip to main content

Description

Executes Luau code during play or server mode, capturing output, errors, and results. Automatically starts the specified mode, runs the code, stops the mode, and returns comprehensive results. Ideal for integration tests and automated playtesting.

Endpoint

run_script_in_play_mode

Parameters

code
string
required
The Luau code to execute during play mode
timeout
number
default:100
Maximum execution time in seconds. Defaults to 100 seconds.
mode
string
default:"play"
The mode to run in: "play" or "server". Defaults to "play".

Response

success
boolean
Whether the code executed successfully without errors
value
string
The string representation of the return value (if successful)
error
string
Error message if the code failed or timed out
logs
array
Array of all captured log messages during execution
logs[].level
string
Message level: "output", "info", "warning", or "error"
logs[].message
string
The log message content
logs[].ts
number
Timestamp relative to execution start
errors
array
Array of error and warning messages only
duration
number
Execution time in seconds
isTimeout
boolean
Whether the execution exceeded the timeout

Examples

Simple test

{
  "code": "print('Test started')\nlocal part = Instance.new('Part')\npart.Parent = workspace\nprint('Part created')\nreturn true"
}
Response:
{
  "success": true,
  "value": "true",
  "logs": [
    {
      "level": "output",
      "message": "Test started",
      "ts": 0.001
    },
    {
      "level": "output",
      "message": "Part created",
      "ts": 0.003
    }
  ],
  "errors": [],
  "duration": 0.15,
  "isTimeout": false
}

Run in server mode

{
  "code": "print('Server test')\nreturn game:GetService('RunService'):IsServer()",
  "mode": "server"
}
Response:
{
  "success": true,
  "value": "true",
  "logs": [
    {
      "level": "output",
      "message": "Server test",
      "ts": 0.001
    }
  ],
  "errors": [],
  "duration": 0.12,
  "isTimeout": false
}

With custom timeout

{
  "code": "wait(3)\nreturn 'done'",
  "timeout": 10
}
Response:
{
  "success": true,
  "value": "done",
  "logs": [],
  "errors": [],
  "duration": 3.1,
  "isTimeout": false
}

Test with error

{
  "code": "error('Something broke')"
}
Response:
{
  "success": false,
  "error": "Something broke",
  "logs": [
    {
      "level": "error",
      "message": "Something broke",
      "ts": 0.001
    }
  ],
  "errors": [
    {
      "level": "error",
      "message": "Something broke",
      "ts": 0.001
    }
  ],
  "duration": 0.05,
  "isTimeout": false
}

Timeout

{
  "code": "while true do wait(1) end",
  "timeout": 5
}
Response:
{
  "success": false,
  "error": "Timed out after 5s — force-stopped play mode",
  "isTimeout": true,
  "duration": 5
}

Notes

  • Studio must not be running when calling this tool
  • The tool automatically starts and stops the specified mode
  • A test runner script is temporarily created in ServerScriptService
  • Messages prefixed with [RbxGenie] are filtered from logs
  • Includes a watchdog timer that force-stops if timeout+5s is exceeded

Build docs developers (and LLMs) love