Debugging and performance
Studio + Cursor workflow for this lesson
Observable outcome: A reproducible symptom becomes a ranked hypothesis, targeted observation, minimal fix, and measured Studio retest.
App roles: Build and inspect non-script instances, run simulations, read server/client Output, use the debugger, and verify behavior in Roblox Studio. Read and edit synchronized Luau, attach narrow file context, and review the saved diff in Cursor. Cursor writes edits to disk immediately; Script Sync may apply them to Studio before you finish reviewing. Stop the simulation first and never treat Cursor's explanation as a gameplay test.
Starting hierarchy and synced files
Create or confirm this in Studio. Scene Parts remain Studio-owned; only the named script folders are synced.
CourseServer and CourseClient folders contain the exact scripts under investigation
Studio Output, debugger, Developer Console, Performance Stats and MicroProfiler supply runtime evidence
Disk file(s): Attach only the smallest relevant files plus sanitized Studio Output; do not attach the whole workspace by default. The suffix is part of the contract: .server.luau creates a server Script, .local.luau creates a LocalScript, and plain .luau creates a ModuleScript. This course does not use .client.luau when it specifically needs a LocalScript.
Predict before asking
State the expected event path and choose the first boundary where evidence can distinguish two plausible causes.
Copy this narrow Cursor prompt
I am debugging this Roblox behavior: [one-sentence symptom]. Relevant files: @[attach exact files]. Expected event path: [client input -> remote -> server validation -> state -> UI]. Studio reproduction: [steps]. Exact sanitized server/client Output: [lines]. Generate ranked hypotheses and one low-noise observation for each. Do not edit yet and do not claim a runtime cause without evidence.
Do not include credentials, cookies, private chats, account details, personal names, or production player data. Attach only the listed synchronized files; Cursor cannot see the full Studio scene merely because it can see scripts.
Review the saved diff
Prefer a few targeted observations over print spam. Review any proposed diff for unrelated changes and remove temporary instrumentation after the cause is verified. Keep the change small enough to explain line by line. If Cursor edits more than requested, stop, revert to your checkpoint, and narrow the prompt. Do not wait for a fictional “accept before sync” step: saved edits may already be visible in Studio.
Test in Studio
Reproduce in the correct Studio mode, capture baseline evidence, apply one minimal change, and rerun the same case plus a regression case. Use a representative real device before performance claims.
Negative case: Ask Cursor for a diagnosis without Output, then compare how much it must guess; use that contrast to improve your evidence packet.
Copy this debugging prompt
Evidence update: [new observations]. Which hypotheses are now ruled out? Propose the smallest targeted change, explain why it matches the evidence, and specify Studio regression tests. Do not broaden the refactor.
Cursor can reason over the supplied evidence, but it cannot operate Studio's debugger or certify that the retest passed.
Learn it yourself
Profile one measured slow path, make no change until you can name the expensive region, then ask Cursor to review a narrow optimization and its behavioral risks.
Checkpoint
After you observe the expected and negative results, Stop the simulation, review the complete diff, and make a small version-control commit or copy a known-good local checkpoint. Record what you personally verified; do not convert an unchecked Studio test into a claim.
Correctness and speed require different questions. “Why did a coin count twice?” is a state-and-events question. “Why does collecting it freeze the screen?” is a timing question. Work on one observable problem at a time, and preserve a small reproduction so you know whether a change helped.
Prerequisites: The co-op rounds project, a saved backup, and the test record from lesson 14.
Outcome: Follow a bug from its visible symptom to the owning script, use a breakpoint without confusing editor state with runtime state, and collect a useful performance baseline.
Trace one event from beginning to end
Use the actual co-op object paths, not an invented generic “game manager”:
Workspace > CoopArena > RoundCoinscontains this round's collectible parts.ServerScriptService > CourseServer > RoundServerhandles touches and updates the shared count.ReplicatedStorage > RoundStateexposes Collected, Target, Status, and TimeLeft attributes.- The LocalScript from lesson 12 reads those attributes and updates the player's interface.
Start a two-client test and collect one coin. Observe the server's Collected attribute, then the two client copies, then the label. Ask where the first wrong value appears. If the canonical server value is correct and only one label is stale, rewriting the round logic is unlikely to help.
Read the first relevant Output error, including its script path and stack trace. Later errors may be consequences. A nil-index error means an assumption about an object or value failed; it does not automatically mean WaitForChild belongs everywhere. Confirm the name, parent, creation timing, and execution side first.
Use a breakpoint for a specific question
In RoundServer, set a breakpoint on the executable line that increments collected. Start Test and touch a coin. Inspect the local player, claimed flag, phase, thisRound, and roundId. The code guards against old-round touches and claims a coin before changing shared progress.
Studio supports breakpoints, watches, call-stack inspection, stepping, and conditional/logpoint variants. Insert a breakpoint in the script gutter next to executable code, then resume when you have the answer. See Studio debugging.
Do not leave several accidental breakpoints enabled and interpret the resulting pauses as a performance regression. Similarly, pausing a simulation is not a substitute for understanding asynchronous scripts. Run the decisive test again without debugger interruption before marking it fixed.
A useful hypothesis is narrow: “The callback runs, but returns because the character is dead.” A weak hypothesis is “Touched is broken.” Inspect the guard that would distinguish them. If an occasional race disappears when paused, use a temporary bounded log with round ID and event order instead of adding arbitrary waits.
Create a baseline before optimizing
Pick one repeatable scene: two players, one round start, all eight coins visible, the same camera angle, and the same device. Record the build, client or server side, graphics setting, player count, and observation duration. Compare the same scenario after one change.
Separate three categories:
- Frame time: Does work cause slow individual frames or repeated stutters?
- Memory: Does usage settle, or grow across repeated rounds and respawns?
- Load time: Is the delay only at join, when assets first appear, or throughout play?
Roblox's Developer Console, Performance Stats, Scene Analysis, and MicroProfiler provide different views. Studio measurements include editor overhead; use an actual Roblox client and a representative lower-powered device before making device-support claims. Identify performance issues
For intuition, 60 frames per second gives about 16.7 milliseconds per frame, while 30 gives about 33.3. An average can hide a conspicuous occasional spike. Do not promise a frame-rate target based on one fast Mac.
Investigate the measured bottleneck
MicroProfiler shows how frame time is spent. Capture the moment with the visible slowdown and inspect the expensive region; compare before and after a targeted change. You can label code sections with debug.profilebegin and debug.profileend when a real investigation needs finer attribution. Do not add per-frame print spam as a measurement tool. MicroProfiler
For this small project, useful checks include:
- Does RoundCoins return to the intended count each round, or are old instances accumulating?
- Are event connections and loops tied to objects that have been removed?
- Is a UI being created once per player or repeatedly on every attribute update?
- Are expensive scans repeated every frame when an event could supply the change?
- Is a visual asset disproportionately complex for its tiny screen presence?
These are hypotheses, not universal diagnoses. Eight coins do not justify a spatial-index rewrite by themselves. A decorative model might dominate rendering while your carefully optimized arithmetic saves nothing visible.
Exercise and completion check
In a copy, deliberately rename RoundState in one client lookup. Reproduce the broken display, identify the mismatch, restore the name, and rerun the case. Then observe several complete rounds and respawns without changing anything. Record whether object count and memory settle; do not call a short increase a leak without checking its lifecycle.
For a family-friendly testing role, ask one person to describe the visible symptom while another records the smallest steps. Avoid turning the session into blame about who “broke” the game.
You are done when one bug has an explained cause and verified fix, one baseline is recorded, and every proposed optimization names the measurement it should improve.
Verification: Official debugging and performance references checked 2026-10-03. No Studio profiling or hardware benchmark was performed for this manual; all measurements are exercises for your own build.
Previous: 15 Saving progress · Next: 17 Assets and Toolbox
Related: 04 Events and debugging · 14 Testing multiplayer · Help context