Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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 the for 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!

2 comments

0

This helped! Thank you!

0

No Problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.