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):
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)
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)