Death Effect GUI not working 2nd time

Issue : It works well the first time but fails to fade to transparent on the second time. (Video for more in depth).

  1. (NOTICE : this is a script that creates the GUI by its own) Video link :
    Link

script Type : Local , Location : StarterPlayerScripts

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local TweenService = game:GetService("TweenService")

local function createScreenGui()
    local screenGui = Instance.new("ScreenGui")
    screenGui.Name = "DeathEffectGui"
    screenGui.ResetOnSpawn = false

    local textLabel = Instance.new("TextLabel", screenGui)
    textLabel.Size = UDim2.new(1, 0, 1, 0)
    textLabel.Text = "WASTED"
    textLabel.TextColor3 = Color3.new(1, 0, 0)
    textLabel.TextScaled = true
	textLabel.BackgroundTransparency = 1
	

    local blackFrame = Instance.new("Frame", screenGui)
    blackFrame.Size = UDim2.new(1, 0, 1, 0)
    blackFrame.BackgroundColor3 = Color3.new(0, 0, 0)
    blackFrame.BackgroundTransparency = 1

    screenGui.Parent = LocalPlayer:WaitForChild("PlayerGui")
    return textLabel, blackFrame
end

local function fadeToBlack(blackFrame)
    local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
    local tween = TweenService:Create(blackFrame, tweenInfo, {BackgroundTransparency = 0})
    tween:Play()
    tween.Completed:Wait()
end

local function fadeToTransparent(blackFrame)
    local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
    local tween = TweenService:Create(blackFrame, tweenInfo, {BackgroundTransparency = 1})
    tween:Play()
    tween.Completed:Wait()
end

local function onCharacterAdded(character)
    local humanoid = character:WaitForChild("Humanoid")
    humanoid.Died:Connect(function()
        local textLabel, blackFrame = createScreenGui()
        textLabel.Visible = true
        fadeToBlack(blackFrame)
        textLabel.Visible = false
    end)
end

LocalPlayer.CharacterAdded:Connect(onCharacterAdded)
if LocalPlayer.Character then
    onCharacterAdded(LocalPlayer.Character)
end

LocalPlayer.CharacterAdded:Connect(function(character)
    local blackFrame = LocalPlayer:WaitForChild("PlayerGui"):FindFirstChild("DeathEffectGui"):FindFirstChildOfClass("Frame")
    if blackFrame then
        fadeToTransparent(blackFrame)
    end
end)

2 Likes

try to print something in here

if blackFrame then
        print("Passed")
        fadeToTransparent(blackFrame)
end

To see if the funtion even runs, or inside the function if you want

1 Like

1st it passed

1 Like

2nd it keeps repeating “Passed”

1 Like

Sorry if im not that great at scripting as this is a code from a group work

1 Like

What are the errors on 2nd phase?

1 Like

No errors
Sorry for the late response something quite bad happen to me

1 Like