Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make my frame fade in and out? I can't make it fade out.

Asked by 5 years ago
Edited 5 years ago
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.

2 answers

Log in to vote
2
Answered by
hellmatic 1523 Moderation Voter
5 years ago
Edited 5 years ago

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
0
That fades out the frame. If you want the frame to fade in, switch 1 and 0 and make .1 a negative (-.1) hellmatic 1523 — 5y
0
note that when this code runs, other code below it won't run until the loop is completed hellmatic 1523 — 5y
0
this fades it instantly as the wait() doesn't have an argument provided to it thebayou 441 — 5y
0
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() hellmatic 1523 — 5y
View all comments (4 more)
0
But this fade is instantaeous thebayou 441 — 5y
0
if you want super smooth fade this isn't the way to do it - refer to my answer thebayou 441 — 5y
0
@thebayou it doesn't fade instantly. I fade my guis with a for loop and never put a number in wait awesomeipod 607 — 5y
0
but you have no control over the duration of the animation thebayou 441 — 5y
Ad
Log in to vote
0
Answered by
thebayou 441 Moderation Voter
5 years ago
Edited 5 years ago

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
0
who cares the for loop is better User#19524 175 — 5y
0
for loop is more efficient awesomeipod 607 — 5y

Answer this question