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?
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.
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