Due to floating point error, it's best not to compare a decimal number to another exact decimal number, as the binary representation of a number can cause what would in theory be two equivalent numbers to be different.
Because of this, when comparing the equality of two decimal numbers, either use an epsilon or use more general operators such as >= and <=.
local gui = script.Parent.Parent.Parent.Frame
script.Parent.MouseButton1Click:Connect(function()
repeat
wait(0.08)
gui.BackgroundTransparency = gui.BackgroundTransparency - 0.1
until gui.BackgroundTransparency <= 0.05
gui.BackgroundTransparency = 0
end)
EDIT
If you want the fade to be super smooth, here's something you could do:
local fadeDuration = 1 - - Change this to however lnog you want the fade animation to be (in seconds)
repeat
local elapsed = wait()
gui.BackgroundTransparency = gui.BackgroundTrasnparency - (elapsed*fadeDuration)/fadeDuration
until gui.BackgroundTransparency <= 0.01
8 comments
That fades out the frame. If you want the frame to fade in, switch 1 and 0 and make .1 a negative (-.1)
note that when this code runs, other code below it won't run until the loop is completed
this fades it instantly as the wait() doesn't have an argument provided to it
adding a number inside the wait() will make the fading appear choppy. As long as the increment is low, there is no need for a number in wait()
But this fade is instantaeous
if you want super smooth fade this isn't the way to do it - refer to my answer
@thebayou it doesn't fade instantly. I fade my guis with a for loop and never put a number in wait
but you have no control over the duration of the animation