Documentation Index Fetch the complete documentation index at: https://mintlify.com/nnaridz/RbxGenie/llms.txt
Use this file to discover all available pages before exploring further.
Overview
run_script_in_play_mode executes custom Luau code in a temporary Play Mode session, collects logs and errors, then automatically stops and returns the results. This is ideal for:
Testing game logic without manual playtesting
Validating scripts in runtime environment
Debugging server-side behavior
Collecting runtime data for analysis
This tool requires StudioTestService, which is only available in Roblox Studio with proper permissions.
Basic Usage
Simple Test
Run a basic script and capture output:
{
"code" : "print('Hello from Play Mode!') \n print('Current time:', os.clock())" ,
"timeout" : 5
}
Return Values
Capture return values from your test code:
{
"code" : "local workspace = game:GetService('Workspace') \n local partCount = #workspace:GetChildren() \n return partCount" ,
"timeout" : 5
}
Testing Game Behavior
Spawn Player and Test Character
{
"code" : "local Players = game:GetService('Players') \n local player = Players:CreateLocalPlayer(0) \n player.CharacterAdded:Wait() \n local character = player.Character \n local humanoid = character:WaitForChild('Humanoid') \n print('Player spawned with health:', humanoid.Health) \n return humanoid.Health" ,
"timeout" : 10
}
Test Part Collision
{
"code" : "local part1 = Instance.new('Part') \n part1.Size = Vector3.new(10, 1, 10) \n part1.Position = Vector3.new(0, 5, 0) \n part1.Parent = workspace \n\n local part2 = Instance.new('Part') \n part2.Size = Vector3.new(5, 5, 5) \n part2.Position = Vector3.new(0, 10, 0) \n part2.Parent = workspace \n\n wait(0.5) \n\n local touching = false \n for _, touchingPart in ipairs(part1:GetTouchingParts()) do \n\t if touchingPart == part2 then \n\t\t touching = true \n\t\t break \n\t end \n end \n\n print('Parts touching:', touching) \n return touching" ,
"timeout" : 3
}
Testing with Multiple Services
Test DataStore Operations
{
"code" : "local DataStoreService = game:GetService('DataStoreService') \n local testStore = DataStoreService:GetDataStore('TestStore') \n\n local testData = { coins = 100, level = 5 } \n testStore:SetAsync('player_123', testData) \n\n local retrieved = testStore:GetAsync('player_123') \n print('Retrieved data:', game:GetService('HttpService'):JSONEncode(retrieved)) \n\n return retrieved.coins == 100" ,
"timeout" : 5
}
DataStore operations in Studio may not work exactly as in production. Use mock data stores for testing when possible.
Test Remote Events
{
"code" : "local ReplicatedStorage = game:GetService('ReplicatedStorage') \n\n local remoteEvent = Instance.new('RemoteEvent') \n remoteEvent.Name = 'TestEvent' \n remoteEvent.Parent = ReplicatedStorage \n\n local eventFired = false \n local receivedData = nil \n\n remoteEvent.OnServerEvent:Connect(function(player, data) \n\t eventFired = true \n\t receivedData = data \n\t print('Event received:', data) \n end) \n\n -- Simulate firing the event \n remoteEvent:FireServer('test_data') \n\n wait(0.1) \n\n return eventFired" ,
"timeout" : 3
}
Error Handling and Debugging
Catching Errors
Request with Error
Response
{
"code" : "local part = workspace.NonExistentPart \n print(part.Size)" ,
"timeout" : 5
}
Safe Error Testing
{
"code" : "local success, result = pcall(function() \n\t local part = workspace.NonExistentPart \n\t return part.Size \n end) \n\n if not success then \n\t print('Caught error:', result) \n end \n\n return success" ,
"timeout" : 5
}
Timeout Handling
{
"code" : "wait(10) \n print('This will never print')" ,
"timeout" : 2
}
Set timeout appropriately for your test. Default is 100 seconds, but most tests should complete in 5-10 seconds.
Long-Running Tests
{
"code" : "local startTime = os.clock() \n local results = {} \n\n for i = 1, 100 do \n\t local part = Instance.new('Part') \n\t part.Parent = workspace \n\t table.insert(results, part.Name) \n\t if i % 10 == 0 then \n\t\t print('Created', i, 'parts') \n\t end \n end \n\n local duration = os.clock() - startTime \n print('Test completed in', duration, 'seconds') \n\n return #results" ,
"timeout" : 30
}
Run Modes
You can specify whether to run in Play Mode or Server Mode:
Play Mode (default)
Server Mode
{
"code" : "print('Running in', game:GetService('RunService'):IsServer() and 'Server' or 'Client', 'mode')" ,
"mode" : "play" ,
"timeout" : 5
}
play : Starts Play Mode (includes client simulation)
server : Starts Run Mode (server-only)
Best Practices
Minimize wait() calls and focus on specific behaviors. Faster tests provide quicker feedback.
Test scripts run in a temporary session that gets cleaned up automatically, but avoid creating excessive instances that could slow down the test.
Use pcall for Error Testing
Wrap potentially failing code in pcall to handle errors gracefully and return useful diagnostics.
Return boolean or numeric values that indicate test success/failure for easy automation.
Use print() statements to track test progress, especially in longer tests.
Common Patterns
Test Suite Runner
{
"code" : "local tests = {} \n local passed = 0 \n local failed = 0 \n\n local function test(name, fn) \n\t local success, err = pcall(fn) \n\t if success then \n\t\t passed = passed + 1 \n\t\t print('✓', name) \n\t else \n\t\t failed = failed + 1 \n\t\t print('✗', name, ':', err) \n\t end \n end \n\n test('Workspace exists', function() \n\t assert(game:GetService('Workspace') ~= nil) \n end) \n\n test('Baseplate exists', function() \n\t assert(workspace:FindFirstChild('Baseplate') ~= nil) \n end) \n\n test('Player spawns', function() \n\t local Players = game:GetService('Players') \n\t assert(#Players:GetPlayers() >= 0) \n end) \n\n print(' \\ nResults:', passed, 'passed,', failed, 'failed') \n return failed == 0" ,
"timeout" : 10
}
Next Steps
Basic Operations Learn basic instance manipulation
Bulk Operations Efficiently modify multiple instances