local gui = script.Parent.Parent.Parent.Frame script.Parent.MouseButton1Click:Connect(function() end) repeat wait(0.08) gui.BackgroundTransparency = gui.BackgroundTransparency - 0.1 until gui.BackgroundTransparency == 0
I've been having trouble achieving this. I do however have achieved making the Frame transition into a visible state. I just can't seem to make it transition back into its invisible state.
Instead of using repeat wait() until
loop, use for i
loop.
for i = 0, 1, .1 do -- first number is the start, second is the finish and third is the increment Frame.BackgroundTransparency = i wait() end --basically the loop starts at 0, then adds .1 until the progress(i) is 1
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() -- I'm assuming lines 06 to 10 were meant to go here? repeat wait(0.08) gui.BackgroundTransparency = gui.BackgroundTransparency - 0.1 until gui.BackgroundTransparency <= 0.05 -- Accommodate for floating point error gui.BackgroundTransparency = 0 -- Reset the background transparency to make sure the gui is completely transparent 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