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

How to make a GUI that would fade out after I pressed a key? (check my script pls)

Asked by 5 years ago
Edited 5 years ago

I have made this GUI that would fade in pressing the Q button. The fade-in works, but I'm not sure how to make the same GUI fade out after pressing the same button.

Here's my script:

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
gui = script.Parent
box = gui.Box
Open = false

function PressQ(key)
    if (key == "q") then
        if (Open == false) then
            box.Visible = true
            for trna = 1,0,-0.1 do
                box.BackgroundTransparency = trna
                wait(.005)
            end
            Open = true
        elseif (Open == true) then
            box.Visible = false
            for trna = 0,1,0.1 do
                box.BackgroundTransparency = trna
                wait(.005)
            end
            Open = false
        end
    end
end

Mouse.KeyDown:connect(PressQ)

1 answer

Log in to vote
0
Answered by 5 years ago

Hello XCVii007r1 !

Problem :

In Your script, on line 17, you set the Visible argument to false . Then right after, you do the fade out for loop. So basically what happened was you were setting the .Visible argument to true, so it would be invisible, then it would change the transparency.

Solution:

To see the fade animation, you need to do thefor loop first, then make it visible.false

Here is the fixed script:

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
gui = script.Parent
box = gui.Box
Open = false

function PressQ(key)
    if (key == "q") then
        if Open == false then
            Open = true
            box.Visible = true
            for trna = 1,0,-0.1 do
                box.BackgroundTransparency = trna
                wait(.005)
            end

        elseif Open == true then
            Open = false -- set it to false here,

            for trna = 0,1,0.1 do -- do the for loop here
                box.BackgroundTransparency = trna
                wait(.005)
            end
         box.Visible = false -- Then set Visible to false.
        end
    end
end

Mouse.KeyDown:connect(PressQ)

I Hope this helped and solved your issue.

If This helped, Please Accept this Answer. Thank You!

0
This helped! Thank you! XCVii007r1 2 — 5y
0
No Problem. tonyv537 95 — 5y
Ad

Answer this question