From 8c5b7592ef80e779ab154bfa21be88d7b690cce3 Mon Sep 17 00:00:00 2001 From: Ygor Leal Date: Thu, 9 Apr 2026 03:27:45 +0200 Subject: [PATCH] fix(menu): handle spectate requests during transition state gracefully (#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. --- resource/menu/client/cl_spectate.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/resource/menu/client/cl_spectate.lua b/resource/menu/client/cl_spectate.lua index 87beed54c..049e0ec91 100644 --- a/resource/menu/client/cl_spectate.lua +++ b/resource/menu/client/cl_spectate.lua @@ -269,9 +269,17 @@ RegisterNetEvent('txcl:spectate:start', function(targetServerId, targetCoords) redmInstructionGroup = makeRedmInstructionalGroup(keysTable) end + -- Wait for any ongoing transition to complete before proceeding (#1084) if isInTransitionState then - stopSpectating() - error('Spectate request received while in transition state') + local attempts = 0 + while isInTransitionState and attempts < 100 do + Wait(50) + attempts = attempts + 1 + end + if isInTransitionState then + debugPrint('Spectate request timed out waiting for transition state') + return sendSnackbarMessage('error', 'nui_menu.player_modal.actions.interaction.notifications.spectate_failed', true) + end end -- check if self-spectate