# Debugging

A bug you saw once you can see again, because a run replays exactly. The editor adds two
ways to look inside it: ask who wrote a value, or stop a script at a line. The engine's
[debugging guide](../guides/debugging.md) covers the same on the command line.

![A Luau script stopped at a breakpoint in the Code view: the line marked in the text, the call path and the values of the function in the dock, and the game beside it at the same step](../files/editor/img/debug.jpg)

## Ask who wrote a value

Start here: most questions need no breakpoint.

1. Go to the moment it looks wrong: drag the timeline, then pick the thing.
2. Open the field's menu in the Inspector and press **Why?**.
3. Press the line in the answer to open it, or **Go to step N** to stand the game at the
   step before the value changed.

**How you know it worked.** The answer names the line of the scene or script that wrote
the value last, since which step, how many times, and what it was before. **Ask the agent
about why** puts that answer into the message you are writing.

## Watch a value over the run

1. In a **Why?** answer, press **Watch**.
2. Look at the timeline.

**How you know it worked.** The value has its own lane, drawn over the whole recorded run.
The game on screen was not touched. A press on the lane asks **Why?** at that step.

## Stop a script at a line

1. Open the script in **Code** and click in the gutter beside a line (or `⌘F8`,
   `Ctrl+F8`).
2. Play. When the line runs, the game stops there, part way through one step.
3. Read the dock: the **call path**, the **values** of the function, and **watches** you
   add (a watch is Luau the engine runs where the script stands).
4. Move on: **Next line** `F8`, **Into the call** `F7`, **Out to the caller** `Shift+F8`,
   **Go on** `F9`.

**How you know it worked.** The tab's head says **Stopped at demo.luau:29 · inside step
257**, the line is marked, and the game beside it names the thing the script was running
for. After **Go on**, the step finishes and the game plays on. No restart was needed to
set the breakpoint.

**Ask about this stop** puts the stop into the message you are writing to the agent:
where, the functions and the values shown. Nothing is sent until you send it.

## When a script raises an error

1. The game stops with a card: ***file* stopped the game**, with the engine's words.
2. Press **Open line N**, or **Fix it for me** to hand the error to the agent.
3. Save the fix.

**How you know it worked.** The game goes on by itself when the fix is saved; everything
up to that step still plays.

## When a test fails

1. Read the card over the picture: the first step that differs, the value, and the line
   that last wrote it.
2. Press **Go there**.

**How you know it worked.** The game stands at that step with the thing picked. See
[the run is the test](play.md#the-run-is-the-test).

## What works for Luau and for C#

| | Luau | C# |
| --- | --- | --- |
| Extra install | None | netcoredbg on your computer |
| Breakpoints | Yes | Yes |
| Where it stopped, the call path | Yes | Yes |
| Values, opened in place | Yes | Yes |
| An expression at the stop | Yes | Yes |
| Next line, into, out, go on | Yes | Yes |

> **Note.** Breakpoints in C# are new. Without netcoredbg installed, a breakpoint in a
> `.cs` file is refused and the game runs on. An exported game has no debugger in it.

## Where the time went

1. Press a bar of the **Step cost** lane on the timeline.
2. Read the **Profiler** tab: the step's stages in order, each script down to its
   functions.

**How you know it worked.** One sentence at the top says what took the most, and a press
on a function opens its line. [Profiling](../guides/profiling.md) has the rest.
