Gui is not showing up on death

I’m trying to make an ending mechanic. However, the GUI doesn’t show up on death.

local me = script.Parent -- ScreenGui
local frame = game.ReplicatedStorage["stored stuff"].gui["death/ending frame"] -- this is a frame that shows up upon death
local gamevalues = game.Workspace["important game values"]

-- these are stringvalues in a folder (gamevalues) in workspace. very important for ending/death info

local description = gamevalues.desc
local endingordeath = gamevalues["e or d"]
local name = gamevalues.name

local plr = game.Players.LocalPlayer

plr.CharacterAdded:Wait() -- this waits for the character so that errors won't error everything

local char = plr.Character
local hum = char:FindFirstChild("Humanoid")

-- this is where everything happens

hum.Died:Connect(function()
	local cam = game.Workspace.CurrentCamera
	
	-- blur is added for dramatication and no other reason
	
	local blur = Instance.new("BlurEffect")
	blur.Parent = cam
	blur.Size = 45
	
	-- the frame is cloned and parented to this screen gui
	
	local cloneframe = frame:Clone()
	cloneframe.Parent = me
	
	-- the text of the labels inside the frame are set to the string values
	
	cloneframe["ending or death"].Text = endingordeath.Value
	cloneframe.name.Text = name.Value
	cloneframe.desc = description.Value
end)

This is what should show up (ignore the unfilled text):

This is what happens instead:

There is unfortunately nothing in the output feed.

Where is the localscript in?

30charlimit

1 Like

In the ScreenGui (the “me” variable)

bonusbonusbonus

1 Like

Is the ResetOnSpawn property checked on the screengui or not?

1 Like

Yes. it’s on.

bonusbonusbonus

1 Like

A random idea but try replacing this:

plr.CharacterAdded:Wait() -- this waits for the character so that errors won't error everything

local char = plr.Character

With this:

local char = plr.Character or plr.CharacterAdded:Wait()

try this :

local me = script.Parent -- ScreenGui
local frame = game.ReplicatedStorage["stored stuff"].gui["death/ending frame"]
local gamevalues = game.Workspace["important game values"]

local description = gamevalues.desc
local endingordeath = gamevalues["e or d"]
local name = gamevalues.name

local plr = game.Players.LocalPlayer


local function showDeathScreen()
	local cam = game.Workspace.CurrentCamera

	local blur = Instance.new("BlurEffect")
	blur.Parent = cam
	blur.Size = 45

	local cloneframe = frame:Clone()
	cloneframe.Parent = me

	cloneframe["ending or death"].Text = endingordeath.Value
	cloneframe.name.Text = name.Value
	cloneframe.desc.Text = description.Value

	me.Enabled = true
end

local function setupCharacter(character)
	local hum = character:WaitForChild("Humanoid")

	hum.Died:Connect(function()
		print("Player has died!")
		showDeathScreen()
	end)
end

if plr.Character then
	setupCharacter(plr.Character)
end

plr.CharacterAdded:Connect(setupCharacter)

and put the script in StarterCharacterScripts

The CharacterAdded does not work on PlayerGui because the gui loads after the character is added.
You can try getting the character directly with LocalPlayer.Character and then get the humanoid with char:FindFirstChildOfClass(“Humanoid”). You can detect the .Died event afterwards.

So, try this code:

local me = script.Parent -- ScreenGui
local frame = game.ReplicatedStorage["stored stuff"].gui["death/ending frame"] -- this is a frame that shows up upon death
local gamevalues = game.Workspace["important game values"]

-- these are stringvalues in a folder (gamevalues) in workspace. very important for ending/death info

local description = gamevalues.desc
local endingordeath = gamevalues["e or d"]
local name = gamevalues.name

local plr = game.Players.LocalPlayer

local char = plr.Character
local hum = char:FindFirstChild("Humanoid")

-- this is where everything happens

hum.Died:Connect(function()
	local cam = game.Workspace.CurrentCamera

	-- blur is added for dramatication and no other reason

	local blur = Instance.new("BlurEffect")
	blur.Parent = cam
	blur.Size = 45

	-- the frame is cloned and parented to this screen gui

	local cloneframe = frame:Clone()
	cloneframe.Parent = me

	-- the text of the labels inside the frame are set to the string values

	cloneframe["ending or death"].Text = endingordeath.Value
	cloneframe.name.Text = name.Value
	cloneframe.desc = description.Value
end)

Thanks for reminding me that that’s how it works. I just removed the plr.CharacterAdded:Wait() and everything finally went to work!

1 Like

Glad that I helped :smile:

30charlimit

1 Like