Debugging

Purpose[edit]

It's not always possible to write functional scripts the first time or even to figure out the problem by looking at them. Sometimes you need to "debug" the script by running it using techniques and tools that provide more information about what went wrong.

Run Modes[edit]

Games are played in "Online Play". While is is useful to test out your games in this mode to get the same experience as a player, this mode can be difficult to debug in. There are other modes available in Studio that allow for more ways to test your place and get feedback on how it is running. These other modes have limitations that you should be aware of when testing.

Pros Cons
  • Tools
    • Output Window
    • Command-line
    • Explorer/Properties
  • Player and Character
  • Build Tools
StudioBuild.png

Studio Run[edit]

RibbonBarRunButton.png

Pressing the Run button in Studio starts Run mode. This mode simulates a Roblox server running your game without any players. This mode is useful for when you want to quickly test how your game starts up and runs scripts that do not involve players.

Pros Cons
  • Tools
    • Output Window
    • Command-line
    • Explorer/Properties
  • Fast and Simple
  • No Output Lost

Studio Play Solo[edit]

RibbonBarPlaySoloButton.png

Pressing the Play Solo button in Studio starts Play Solo mode. This mode simulates a server running with a single player in it that you control. This mode is useful for quickly testing player actions in your game. Note that this mode does NOT simulate the separation between Server and Client and thus will not properly accurately simulate a game with Experimental Mode turned off.

Pros Cons
  • Tools
    • Output Window
    • Command-line
    • Explorer/Properties
  • Launches fairly quickly
  • Studio Edits not lost if crashed
  • Player and Character

Test -> Start[edit]

RibbonBarStartButton.png

Pressing Start (in the Test view in Studio) will create a simulated server much like Run does. With Start however you can also specify a number of generic players to add to the game. A new instance of Studio will launch per each player and one for the server when hitting Start. This mode very closely simulates your game running on Roblox and is ideal for testing multiple player interactions and client/server features like Remote Events. Note that this mode is still offline and will not have access to online features.

Pros Cons
  • Tools (Server only)
    • Output Window
    • Command-line
    • Explorer/Properties
  • Most like online mode
  • Studio Edits not lost if crashed
  • Multiple Player(s) and Character(s)
  • LocalScripts have no tools

Tools[edit]

Roblox contains a number of debugging tools that can help you analyze failing (or even working) scripts.

Output[edit]

Main article: Output

The Output window is one of the most powerful debugging tools. It displays any errors captured from running scripts, messages from Roblox game code, and user-defined messages and errors. It can be useful to include print() and error() calls at key places in your scripts so you can see messages in the Output window.

The functions coroutine.resume(), pcall(), and xpcall() can return runtime error messages (which you can print) and prevent script errors from breaking the script.

To open the Output window in Studio, click on the View tab and then on Output. When running a game you do not have access to Studio's Output window, but you can still get Local and Server output using the DeveloperConsole.

Lua Debugger[edit]

Main article: Lua debugger

Like most IDEs, Roblox Studio includes a debugger you can use to pause a script so you can inspect it while it is running. This allows you to stop a script at specific points and run it step by step to see how it behaves.

Command Line[edit]

Main article: Command Line

The Command Line in Studio provides a powerful debug tool. It allows you to test out possible script commands and to make adjustments to the game while it is running.

Explorer/Properties[edit]

The Explorer and Properties windows can be used in Studio to see what objects exists at a given time. It can help you see if certain properties were inadvertently changed by a script.

Log Files[edit]

Another feature of Roblox that can be invaluable to debugging is the log files. Whenever a script running on your computer prints or has an error, this message is recorded in a log file. These files are located in different places depending on the Operating System and usually in hidden folders.

Windows XP, Vista, Windows 7, 8, 10: %LOCALAPPDATA%\Roblox\logs

Vista Alternate Location: C:\Program Files (x86)\Roblox\logs

These are the following log files that Roblox generates:

log_XXXXXX.txt - This is the first log file for the Roblox instance (you get 1 instance if playing online, solo, or directly in studio; 2 or more if using start starter/start player). It contains some Roblox startup debug and the "lost" messages from the first output window.

log_XXXXXX_Roblox_TaskScheduler_Thread Y_Z.txt - This created when character joins or at a similar point on the server. It contains all the rest of the log and error messages.

log_XXXXXX_G3D.txt - Debug messages for 3D engine.

log_XXXXXXgfx_d3d.txt - Debug messages for DirectX and Video driver.

log_XXXXXX_rbx_thread_YYYY.txt - Roblox built-in game script logs.

See Also[edit]

Common Scripting Mistakes