For loop do script help

So I am trying to make a nice fade in and fade out GUI that happens when I call on it but there is one problem I am having. I have made it fade out by using the code below but I don’t know how to make it fade in. I need some help with this and I have already tried by -1 and -60 and that didn’t work. Even when I but the UI to start at a transparency of 1, it changes itself to fade out so I need help with this.

This isn’t anything changing it before this part of the script.

for loop = 1, 60 do
    	bg.BackgroundTransparency = loop/60
    	game:GetService("RunService").Stepped:Wait()
    end
1 Like

for fading in you gotta think backwards. since we know at transparency of 1 its invisible. and at transparency 0 its fully visible.
with that being said:

for loop = 1, 60 do
    	bg.BackgroundTransparency = 1 - (loop/60)
    	game:GetService("RunService").Stepped:Wait()
end
1 Like

Ok, I’ve tested it and it works. Thank you so much.

1 Like

Just to add on to loops, you can also reformat Lolify’s solution as the following:

for i = 60, 1, -1 do
    bg.BackgroundTransparency = loop/60
    game:GetService("RunService").Stepped:Wait()
end

This is identical to the code that Lolify posted, except that the loop starts at 60 and decrements by 1 until it reaches 1.