GUI Script Only Plays Once

Hey there,
I’ve recently been working on a game, and I’ve created a custom death screen. What will happen is when the player dies, text will appear, and a background will fade in, while the text color turns red. Next, the text will change, as well as its color, and all GUI elements fade out, once the player has reset.

This all seems to be working completely fine, although it only works the first time I try it out. The GUI does not reset on spawn, and I’m quite certain that my script should work properly. Any help would be appreciated, thanks!

I have provided my script, as well as a screenshot of the GUI elements in the explorer. If anyone could help me, that would be greatly appreciated! Thank you,
— Spagheters

Gui Elements
image

Script

local TweenService = game:GetService("TweenService")

local Background = script.Parent.Frame
local Text = Background.Notice

local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)

local ColorGoal = {}
ColorGoal.TextColor3 = Color3.fromRGB(255, 35, 35)

local InBackgroundGoal = {}
InBackgroundGoal.BackgroundTransparency = 0

local OutBackgroundGoal = {}
OutBackgroundGoal.BackgroundTransparency = 1

local TextGoal = {}
TextGoal.TextTransparency = 1

local BackgroundInTween = TweenService:Create(Background, tweenInfo, InBackgroundGoal)
local BackgroundOutTween = TweenService:Create(Background, tweenInfo, OutBackgroundGoal)

local ColorTween = TweenService:Create(Text, tweenInfo, ColorGoal)
local TextTween = TweenService:Create(Text, tweenInfo, TextGoal)


local function typewrite(textlabel, text)
	for i = 1, #text do
		textlabel.Text = string.sub(text, 1, i)
		wait(.05)
	end
end


game.Players.LocalPlayer.Character:WaitForChild('Humanoid').Died:connect(function()
	Text.TextColor3 = Color3.fromRGB(255, 255, 255)
	Text.Text = ''
	Text.TextTransparency = 0
	Background.BackgroundTransparency = 1
	
	wait(2)
	
	ColorTween:Play()
	typewrite(Text, 'Test Success = nil.')
	BackgroundInTween:Play()
	
	wait(2)
	
	Text.TextColor3 = Color3.fromRGB(255, 255, 255)
	typewrite(Text, 'Rebooting...')
	
	wait(1)
	
	TextTween:Play()
	BackgroundOutTween:Play()
	
	wait(2)
	
	Text.TextColor3 = Color3.fromRGB(255, 255, 255)
	Text.Text = ''
	Text.TextTransparency = 0
	Background.BackgroundTransparency = 1
end)

When the player respawns, a new Humanoid is created. You’re still listening for .Died on the old, non-existent Humanoid. You need to make sure you’re listening for .Died on the new Humanoid. You can do this by storing the Humanoid as a variable and updating it every time the player dies.

Try this.

local TweenService = game:GetService("TweenService")

local Background = script.Parent.Frame
local Text = Background.Notice

local Humanoid = game.Players.LocalPlayer.Character:WaitForChild('Humanoid')

local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)

local ColorGoal = {}
ColorGoal.TextColor3 = Color3.fromRGB(255, 35, 35)

local InBackgroundGoal = {}
InBackgroundGoal.BackgroundTransparency = 0

local OutBackgroundGoal = {}
OutBackgroundGoal.BackgroundTransparency = 1

local TextGoal = {}
TextGoal.TextTransparency = 1

local BackgroundInTween = TweenService:Create(Background, tweenInfo, InBackgroundGoal)
local BackgroundOutTween = TweenService:Create(Background, tweenInfo, OutBackgroundGoal)

local ColorTween = TweenService:Create(Text, tweenInfo, ColorGoal)
local TextTween = TweenService:Create(Text, tweenInfo, TextGoal)


local function typewrite(textlabel, text)
	for i = 1, #text do
		textlabel.Text = string.sub(text, 1, i)
		wait(.05)
	end
end


Humanoid.Died:connect(function()
	Text.TextColor3 = Color3.fromRGB(255, 255, 255)
	Text.Text = ''
	Text.TextTransparency = 0
	Background.BackgroundTransparency = 1
	
	wait(2)
	
	ColorTween:Play()
	typewrite(Text, 'Test Success = nil.')
	BackgroundInTween:Play()
	
	wait(2)
	
	Text.TextColor3 = Color3.fromRGB(255, 255, 255)
	typewrite(Text, 'Rebooting...')
	
	wait(1)
	
	TextTween:Play()
	BackgroundOutTween:Play()
	
	wait(2)
	
	Text.TextColor3 = Color3.fromRGB(255, 255, 255)
	Text.Text = ''
	Text.TextTransparency = 0
	Background.BackgroundTransparency = 1
	Humanoid = game.Players.LocalPlayer.Character:WaitForChild('Humanoid')
end)

I haven’t tested this - if it still doesn’t work, listen for Player.CharacterAdded and set the Humanoid value then.

I tried it out, and sadly it has not worked, although I do appreciate the effort, thanks!

game.Players.LocalPlayer.Character:WaitForChild('Humanoid').Died:connect(function() When the player dies, it won’t check for the old Humanoid. It’s clearly self explanatory.

Try this:

local TweenService = game:GetService("TweenService")

local Background = script.Parent.Frame
local Text = Background.Notice

local Player = game.Players.LocalPlayer

local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)

local ColorGoal = {}
ColorGoal.TextColor3 = Color3.fromRGB(255, 35, 35)

local InBackgroundGoal = {}
InBackgroundGoal.BackgroundTransparency = 0

local OutBackgroundGoal = {}
OutBackgroundGoal.BackgroundTransparency = 1

local TextGoal = {}
TextGoal.TextTransparency = 1

local BackgroundInTween = TweenService:Create(Background, tweenInfo, InBackgroundGoal)
local BackgroundOutTween = TweenService:Create(Background, tweenInfo, OutBackgroundGoal)

local ColorTween = TweenService:Create(Text, tweenInfo, ColorGoal)
local TextTween = TweenService:Create(Text, tweenInfo, TextGoal)


local function typewrite(textlabel, text)
	for i = 1, #text do
		textlabel.Text = string.sub(text, 1, i)
		wait(.05)
	end
end

Player.CharacterAdded:Connect(function(chr)
	chr:WaitForChild("Humanoid").Died:connect(function()
		Text.TextColor3 = Color3.fromRGB(255, 255, 255)
		Text.Text = ''
		Text.TextTransparency = 0
		Background.BackgroundTransparency = 1

		wait(2)

		ColorTween:Play()
		typewrite(Text, 'Test Success = nil.')
		BackgroundInTween:Play()

		wait(2)

		Text.TextColor3 = Color3.fromRGB(255, 255, 255)
		typewrite(Text, 'Rebooting...')

		wait(1)

		TextTween:Play()
		BackgroundOutTween:Play()

		wait(2)

		Text.TextColor3 = Color3.fromRGB(255, 255, 255)
		Text.Text = ''
		Text.TextTransparency = 0
		Background.BackgroundTransparency = 1
	end)
end)

I tried this one out, and now it appears that the GUI does not function at all.

I’m probably being really stupid and missing something obvious then, I’m running on about 5 hours of sleep. Sorry I couldn’t be of more assistance.

No worries, I appreciate the help.