Frame in death screen UI becomes invalid after death?

Hello, I am trying to achieve a death screen appearing everytime humanoid dies obviously, however, a frame of the GUI somehow becomes invalid despite it being in playergui, with seemingly nothing affecting it. This phenomenon happens after the player dies once, but every other client effect works, including SFX and lighting changes. What am I doing wrong?

How it should look like (first death only)

After the first death

Scripts/screenshots
image
image
image

Main code below

local players = game:GetService("Players")

local player = players.LocalPlayer

local ts = game:GetService("TweenService")

local deathui = game.StarterGui.DeathUI:Clone()

local playergui = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')

local Bottomframe = deathui:WaitForChild("BottomFrame")

local Topframe = deathui:WaitForChild("TopFrame")

local lighting = game:GetService("Lighting")




deathui.Parent = playergui

player.CharacterAdded:Connect(function(char)
char:WaitForChild("Humanoid").Died:Connect(function()
		script.Parent.Parent.CameraMaxZoomDistance = 10
		script.Parent.Parent.CameraMinZoomDistance = 10
Bottomframe.Visible = true
		Topframe.Visible = true
		frametween:Play()
		frametween2:Play()
		deadtween:Play()
		deadtween2:Play()
		skulltween:Play()
		game.SoundService.DeathMusic:Play()
		lighting.DeathFX.Enabled = true
		lighting.DeathDPF.Enabled = true
			print('ded')

end)

	player.CharacterAdded:Connect(function()
		script.Parent.Parent.CameraMaxZoomDistance = .5
		script.Parent.Parent.CameraMinZoomDistance = .5
	game.SoundService.DeathMusic:Stop()
Bottomframe.Visible = false
		Topframe.Visible = false
		lighting.DeathFX.Enabled = false
		lighting.DeathDPF.Enabled = false
		deathui.TopFrame.RespawnText.Position = UDim2.new(0.849, 0,0.424, 0)
		deathui.TopFrame.DeadText.Position = UDim2.new(0.835, 0,0.194, 0)
		end)	
end)
1 Like

A couple of things.
(1) Why do you have a player.CharacterAdded event within another player.CharacterAdded event? If the nested event’s purpose is to reset GUI and other client values, then what’s the purpose of keeping it within a secondary event? If you put that code in the larger function, it should run just as fine.
(2) A follow up on (1), but there should be no need for you to have to manually reset the GUIs after the player dies, assuming that the player dies conventionally, which it seems to do. ScreenGuis (and all guis for that matter) have a property called “ResetOnSpawn”, which will bring the contents of the gui back to their original states.

Given all of this, your altered code should look something like this:

local players = game:GetService("Players")

local player = players.LocalPlayer

local ts = game:GetService("TweenService")

local deathui = game.StarterGui.DeathUI:Clone()

local playergui = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')

local Bottomframe = deathui:WaitForChild("BottomFrame")

local Topframe = deathui:WaitForChild("TopFrame")

local lighting = game:GetService("Lighting")




deathui.Parent = playergui

player.CharacterAdded:Connect(function(char)
	script.Parent.Parent.CameraMaxZoomDistance = .5
	script.Parent.Parent.CameraMinZoomDistance = .5
	lighting.DeathFX.Enabled = false
	lighting.DeathDPF.Enabled = false
	game.SoundService.DeathMusic:Stop()
	char:WaitForChild("Humanoid").Died:Connect(function()
		script.Parent.Parent.CameraMaxZoomDistance = 10
		script.Parent.Parent.CameraMinZoomDistance = 10
		Bottomframe.Visible = true
		Topframe.Visible = true
		frametween:Play()
		frametween2:Play()
		deadtween:Play()
		deadtween2:Play()
		skulltween:Play()
		game.SoundService.DeathMusic:Play()
		lighting.DeathFX.Enabled = true
		lighting.DeathDPF.Enabled = true
		print('ded')

	end)
end)

I’m guessing the reason you were getting that error was because you nested the player.CharacterAdded event, and therefore was still looking for the old TopFrame before the new one was replicated.

Just ensure that deathui’s ResetOnSpawn property is true.

2 Likes

This does make the code more efficient, but even with ResetOnSpawn true, the ui still doesn’t pop up again. Topframe however does not error anymore in output

1 Like

Is the ScreenGui property for ResetOnSpawn true?

1 Like

Yes, the screengui property for resetonspawn is true

1 Like

Can you show us a video of this occurring?

Problem was fixed ; rewrote as a localscript in startergui with a separate handler