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

how would i make a button that fades in when i click it and fades out when i click it again?

Asked by 4 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

I want to make a Text Button fade in upon first click and fade out when you click it again. i have tried many solutions but i cant get the button to fade in when i click it i can only get it to fade out.

0
I do not currently have any code for this. Skribb11es 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Do this:

local button = script.Parent
local debounce = false
local faded = false

button.MouseButton1Click:Connect(function()
    if debounce == false then
        debounce = true
        if faded == false then
            faded = true
            for i = 0, 1, 0.05 do
                button.BackGroundTransparency = i
                button.TextTransparency = i
                wait(.05)
                debounce = false
            end
            return -- returning to the begenning of the function to not run the following lines after setting "faded" to true
            else -- if faded = true
            faded = false
            for i = 1, 0, -0.05 do
                button.BackGroundTransparency = i
                button.TextTransparency = i
                wait(.05)
            end
            debounce = false
        end
    end
end)

This code has to be inserted in a localscript, inside the button you want the player to click.

Hope this helped!

Ad

Answer this question