Gui Fade Out on Respawn Not Working

So I have this script where you hit a brick, it checks if the humanoid hp is 0, then fades out.
The problem is I can’t find any way to make it fade back in.


local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

if player then

if hit.Parent.Humanoid.Health == 0 then

local gui = game.ReplicatedStorage:WaitForChild("Black"):Clone()

gui.IgnoreGuiInset = true

gui.Black.BackgroundTransparency = 1

gui.Parent = player.PlayerGui

local toTween = gui.Black

local tweenInfo = TweenInfo.new()

local goal = {}

goal.BackgroundTransparency = 0

local tween = game:GetService("TweenService"):Create(toTween, tweenInfo, goal)

wait(1)

tween:Play()

end

end

end)

If you want the GUI to fade back in immediately after fading out, you can use the Completed event of tweens:

local fadeOutTween = TweenService:Create(toTween, tweenInfo, {BackgroundTransparency = 0})
local fadeInTween = TweenService:Create(toTween, tweenInfo, {BackgroundTransparency = 1})

fadeOutTween.Completed:Connect(function()
    --maybe a delay here
    fadeInTween:Play()
    fadeOutTween:Destroy()
end)

wait(1)

fadeOutTween:Play()

What this does is play the tween that fades the GUI back in when the fade-out tween ends.

1 Like