Independent Technical Resource & Anti-Phishing ShieldVerified Safe
RobloxDownloads.com is an independent diagnostic database. We do NOT host executable binaries (.exe, .dmg, .apk). All download action links redirect directly to verified first-party official sources (Roblox Corporation, Microsoft Store, Apple App Store, Google Play).
PlayerGui resets on respawn & UI disappears: ResetOnSpawn & ScreenGui Lifecycle
When a player dies and respawns, Roblox by default wipes all ScreenGuis in PlayerGui and clones fresh copies from StarterGui. This destroys active UI script variables and breaks event connections. Fix this by disabling ResetOnSpawn on persistent ScreenGuis.
PLAYERGUI_RESET_ON_SPAWN_BUG is a Luau VM and Roblox Studio diagnostic event triggered by "attempt to index nil with 'PlayerGui' (or UI disappears upon player death)". When a player dies and respawns, Roblox by default wipes all ScreenGuis in PlayerGui and clones fresh copies from StarterGui. This destroys active UI script variables and breaks event connections. Fix this by disabling ResetOnSpawn on persistent ScreenGuis.
| Telemetry Metric | Verified Value |
|---|---|
| Error Signature | attempt to index nil with 'PlayerGui' (or UI disappears upon player death) |
| Fault Classification | RUNTIME_NIL_EXCEPTION (Replication & Hierarchy) |
| Affected Subsystems | PlayerGui Service, ScreenGui Lifecycle, StarterGui |
| Engine Verification | Studio 0.650+ / Luau 2026 Engine |
| Quick Remediation | Unchecking ResetOnSpawn ensures the ScreenGui and all child elements persist across character deaths without being destroyed. |
attempt to index nil with 'PlayerGui' (or UI disappears upon player death)This exact red trace is logged when the Luau VM or engine runtime encounters a thread halt, unhandled nil reference, or cloud quota block.
Deep-Dive Architectural Root Cause
Every ScreenGui in StarterGui has a property named ResetOnSpawn which defaults to true. When a character dies, the Roblox core GUI manager deletes the player's existing GUI hierarchy and creates brand-new instances. If local scripts stored references to UI buttons outside the character lifecycle, those references become invalid pointers to destroyed instances.
💻 Code Implementation Comparison
Inspect the flawed snippet causing the runtime fault vs. the hardened, production-grade Luau solution.
-- ❌ BROKEN: ScreenGui has ResetOnSpawn = true, but script is in StarterPlayerScripts
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local shopButton = playerGui:WaitForChild("ShopGui"):WaitForChild("OpenButton")
-- On first death, ShopGui is destroyed and recreated, but shopButton still points to the DEAD button!
shopButton.Activated:Connect(function()
print("This will stop working after player respawns!")
end)Halts thread execution, creates memory leaks, or trips engine watchdogs when unexpected nil states occur.
-- ✅ PRODUCTION FIX: Persistent UI Architecture
-- 1. In Roblox Studio Properties Window:
-- Select your ScreenGui inside StarterGui -> Uncheck "ResetOnSpawn"
-- 2. In LocalScript (placed inside StarterPlayerScripts or ReplicatedFirst):
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("PersistentShopGui") :: ScreenGui
local openButton = screenGui:WaitForChild("OpenButton") :: TextButton
openButton.Activated:Connect(function()
print("✅ This connection survives unlimited respawns because ResetOnSpawn is false!")
end)Zero unhandled yields, guarded type narrowing, safe fallback paths, and production reliability.
🛠️ Engineering Resolution Steps
- 1Unchecking ResetOnSpawn ensures the ScreenGui and all child elements persist across character deaths without being destroyed.
- 2Placing UI control scripts in StarterPlayerScripts prevents scripts from re-running and creating duplicate event listeners upon each death.
- 3Conserves client memory and eliminates interface flicker during the respawn sequence.
⚙️ Roblox Studio Configuration Checklist
❓ Frequently Asked Developer Questions
When SHOULD ResetOnSpawn remain checked (true)?
Keep ResetOnSpawn enabled only for temporary gameplay overlays, such as a health bar or killcam that specifically needs a fresh reset for the new character.
Related Roblox Studio & Luau Diagnostics
Explore other compiler warnings, runtime exceptions, and developer telemetry tools.