Can't figure out fade frame after transparency = 0

Hello,

I want to get this frame to fade in which I’ve got down the fade out when the frame has finished fading to a transparency of 0.

I’ve created this GUI and I can fade the first part, but when the frame hits a transparency of 0 I want it to fade back out.

It’ll just stay at a transparency of 0 instead of fading out and there are no error codes in the output.

Here is my script:

Thanks!

It’s necessary that you should put an if statement in a while loop like this

--Insert your first 4 lines of script here
while wait(0.01) do
            if MainFrame.BackgroundTransparency <= 0 then
                       MainFrame.BackgroundTransparency += 0.01
            elseif MainFrame.BackgroundTransparency >= 10 then
                      MainFrame.BackgroundTransparency -= 0.01
            end
end

Actually, you could use a For Loop, or TweenService. You can read more about loops here, and Tweens here.

Here is the solution:

local MainFrame = script.Parent
local LoadingGui script.Parent.Parent

wait(2)

for i=0, 1, -0.01 do
    MainFrame.BackgroundTransparency -= 0.01
    wait(0.01)
end

You can also use TweenService. Here is a (better) example with TweenService:

local MainFrame = script.Parent
local LoadingGui script.Parent.Parent

wait(2)
game:GetService("TweenService"):Create(MainFrame, TweenInfo.new(1), {Transparency = 1}):Play()

The :Create function takes three arguments:

  1. Instance
  2. TweenInfo
  3. Property

You can read more about tweens here.

1 Like

It’s going in the negatives and will not add transparency.

Then you can just try recanman’s suggestion