Help to make a fade out

Hi Developers, I have made a simple easy line of code and I need help to make a fade out animation for it, Here is my code.

wait(5) script.Parent.Enabled = false script.Parent.Parent.MenuGui.Enabled = true

2 Likes

First, answer these:

  1. How long should the animation be?
  2. What kind of fade out do you want?
  3. What are you trying to animate?
1 Like

A loading screen.

A black fade out.

2s.

You can use TweenService.

game:GetService("TweenService"):Create(FrameItself, TweenInfo.new(2), {BackgroundTransparency = 1}):Play()

1 Like

localscript as a child/parent of the screengui

local black = Instance.new("Frame")
black.Size = Udim2.new(1, 0, 1, 0)
black.BackgroundTransparency = 1
black.Parent = script.Parent --or script.LoadingScreen if it is parent

local ts = game:GetService("TweenService")

function FadeIn()
    ts:Create(black, TweenInfo.new(2), {BackgroundTransparency = 0}):Play()
end

function FadeOut()
    ts:Create(black, TweenInfo.new(2), {BackgroundTransparency = 1}):Play()
end
1 Like
local black = script.Parent.Frame

wait(5)
script.Parent.Enabled = false
local ts = game:GetService("TweenService")

function FadeIn()
	ts:Create(black, TweenInfo.new(2), {BackgroundTransparency = 0}):Play()
end

function FadeOut()
	ts:Create(black, TweenInfo.new(2), {BackgroundTransparency = 1}):Play()
script.Parent.Parent.MenuGui.Enabled = true
end

Ain’t working…

Is black a frame or screengui?

2 Likes

you need to call the functions

local black = script.Parent.Frame

local ts = game:GetService("TweenService")

function FadeIn()
	ts:Create(black, TweenInfo.new(2), {BackgroundTransparency = 0}):Play()
end

function FadeOut()
	ts:Create(black, TweenInfo.new(2), {BackgroundTransparency = 1}):Play()
script.Parent.Parent.MenuGui.Enabled = true
end

task.wait(5)
script.Parent.Enabled = false
FadeOut()
1 Like

TowerDefenserGUIMENU (no cam scripts.)

Also, from what I’m seeing, the ScreenGui is being disabled before the fade out, meaning it won’t actually play an animation since the frame is just getting hidden

2 Likes

Aight, many issues here. First of all, you have so many frames and different transparency properties. You’re changing the blackframe, but the blackframe isnt visible initially so I doubt its the one you want to fade. Instead, you probably want to fade the image, which means you need to access the imagetransparency property of the BGChange img not the BackgroundTransparency of the blackframe. All frames you dont want to animate should then also be set to be transparent now, otherwise you’ll have to create tweens for those too and play them simultaneously.

The other problem is that you disable the Gui right after starting the tween, so it’ll never finish playing before just disappearing anyway.

Instead you need to do something like

function FadeOut()
	local tween = ts:Create(black, TweenInfo.new(2), {BackgroundTransparency = 1})
	tween:Play()
	tween.Completed:Wait()
end

task.wait(5)
FadeOut()
script.Parent.Enabled = false

Keep in mind this code isn’t changed to access the image and its imagetransparency instead.

2 Likes

In that case:

local black = Instance.new("Frame")
black.Size = Udim2.new(1, 0, 1, 0)
black.BackgroundTransparency = 1
black.Parent = script.Parent --or script.LoadingScreen if it is parent

local ts = game:GetService("TweenService")

function FadeIn()
    ts:Create(black, TweenInfo.new(2), {BackgroundTransparency = 0}):Play()
end

function FadeOut()
    ts:Create(black, TweenInfo.new(2), {BackgroundTransparency = 1}):Play()
end

task.wait(5)
pcall(function()
    for _, v in script.Parent:GetDescendants() do
        v.Transparency = 1
    end
end)

FadeOut()
task.wait(2)
script.Parent.Enabled = false
1 Like

Oh, alright then, ill check it if it works.

That makes zero sense, you attempt to set things invisible (Transparency isn’t a property of any GUI elements. It’s for parts), just to fade them out after?

2 Likes

Uh, that won’t change anything. That’s just a pretty bad way of disabling UIStrokes and UIGradients.

Yeah that should work

1 Like

Technically it is but that code is still irrelevant

1 Like

Forgot about UIStrokes and UIGradients, but yeah. Either way, no this below WON’T work.

FadeOut()
task.wait(2)
script.Parent.Enabled = false

The wrong frame is being accessed, blackframe is behind another frame so it’s entirely pointless to fade it out. It should just be set as transparent. And OP probably actually needs to create a tween for every visible part of their loading screen instead.

So OP, loop over every element of your gui then for each of them create a new tween that handles their respective transparency property whichever type it is. You’re going to have quite a few, and for some probably even several.

Save all the tweens to a table, and then when all have been created, loop over that table and play all of them

2 Likes

Transparency is a valid property for every single guiobject including frames and textlabels and whatnot.

2 Likes

Not a frame, a imageLabel, though i just want it like this, the whole loading gui fades.

I stand somewhat corrected, even if it’s deprecated. However, it’s still hardly applicable here as it’ll return the background transparency of an imagelabel and it’s the imagetransparency the OP needs to modify lmao.

2 Likes