Issue : It works well the first time but fails to fade to transparent on the second time. (Video for more in depth).
-
(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)