Using the Lua Debugger
Using the Lua Debugger
The Lua debugger is a tool designed to give Roblox developers the same utilities as any developer expects from an IDE (Integrated Development Environment). It’s enabled by default, however it can be toggled on or off through Roblox Studio’s Settings menu.
What is a Debugger?
A debugger is a tool which helps developers check that their code is functioning properly. Some debugger functionality can be replicated with
print() statements that verify when specific code executes, but a debugger lets you put breakpoints in your scripts without modifying the code. In addition, the application will stop at breakpoints, letting you inspect the state of the program and even the values of certain variables at that point.
Breakpoints are “checkpoints” within a script. If a breakpoint is set for a line of code, a running Roblox game will pause when it tries to execute that line.
To set a breakpoint within a script:
- Open a script inside Roblox Studio.
- Click to the left of any line where you want to pause execution of the script. This will create a red dot indicating a breakpoint.
You can see all of the breakpoints you’ve set by clicking on Breakpoints from the View tab. This will open the Breakpoints window where can enable/disable specific breakpoints (or all breakpoints), remove breakpoints, and see which script each breakpoint is in.
Stepping Through Code
When a script is paused at a breakpoint, you can continue executing the script line by line. This lets you closely monitor how variables are changed and which functions are called. There are three ways to step through code, all available from in the Script Menu tab:
|Step Into||The Step Into button moves the debugger into the function on the current line. If there is no function on the current line, the debugger will move to the next line.|
|Step Over||The Step Over button moves the debugger to the next line of code, not moving into functions.|
|Step Out||The Step Out button moves the debugger out of the current function and to the next line of code after the function was initially called. If the current line is not inside a function, this button will move to the next line.|
You can also tell the debugger to “watch” variables, keeping track of their value when you hit breakpoints. To add a variable to the watch list, simply highlight it and click the Add Watch button from the Script Menu tab. This will open the Watch window where you can monitor the variable’s value as you step through breakpoints.
The Call Stack window, accessible from the View tab, tells you exactly where in your code the game currently is (when paused or at a breakpoint). If the current line of code exists inside a function that was called from another function, the stack will show the order in which the functions were called, along with the line number where the call was made.
Debugging Client Scripts
By default, the Lua debugger only focuses on server-side
Script|Scripts, not on client-side
LocalScript|LocalScripts. This means that you can’t debug
LocalScript|LocalScripts while testing your game in Client mode during a
articles/game testing|Play Solo simulation.
To debug client-side
LocalScript|LocalScripts instead of server-side
Script|Scripts, you can enable the Debug Client in APS Mode setting within Studio. This will allow you to insert breakpoints, step through code, and inspect the call stack of client-side code.
LocalScript|LocalScripts, you cannot debug server-side
Script|Scriptsor swap between the two modes during a single execution. To return to server-side debugging, simply disable Debug Client in APS Mode in Studio's settings.