Skip to content

fix(menu): handle spectate requests during transition state gracefully#1109

Open
YgorLeal wants to merge 1 commit into
citizenfx:developfrom
YgorLeal:fix/spectate-transition-race
Open

fix(menu): handle spectate requests during transition state gracefully#1109
YgorLeal wants to merge 1 commit into
citizenfx:developfrom
YgorLeal:fix/spectate-transition-race

Conversation

@YgorLeal
Copy link
Copy Markdown

@YgorLeal YgorLeal commented Apr 9, 2026

Summary

Fixes #1084 — Spectate no longer crashes with a script error when rapidly cycling through players.

Problem

When quickly pressing up/down arrows to cycle spectated players, a new txcl:spectate:start event could arrive while the previous transition (screen fade, collision loading) was still in progress. The handler called stopSpectating() followed by error(), which produced:

SCRIPT ERROR: @monitor/resource/menu/client/cl_spectate.lua:274: Spectate request received while in transition state

This left the player with a black screen or broke spectate entirely.

Solution

Instead of erroring immediately, the handler now waits up to 5 seconds (100 attempts x 50ms) for the ongoing transition to complete. If the transition finishes in time, the new spectate request proceeds normally. If it times out, a user-friendly snackbar error is shown instead of a script crash.

Testing

  1. Start spectating a player
  2. Rapidly press up/down arrow keys to cycle through players
  3. Spectate should transition smoothly without script errors or black screens
  4. If a transition takes too long, a "spectate failed" message should appear instead of crashing

citizenfx#1084)

When rapidly cycling through spectated players, a new spectate request
could arrive while the previous transition was still in progress. The
old code called stopSpectating() + error(), causing a script error and
black screen.

Now the handler waits up to 5 seconds for the ongoing transition to
complete before proceeding. If it times out, it shows a user-friendly
error message instead of crashing.
@YgorLeal YgorLeal requested a review from tabarra as a code owner April 9, 2026 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant