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

Fade frame transparency on TextButton click?

Asked by 4 years ago

I found this script that pretty much adds a fade like effect when you either spawn or die, but how would i make it so it fades to black, and then back to transparent when i click a TextButton?

script:

fade = script.Parent

fadeGoal = 0

fadeRate = 0.01



function updateFade()

local current = fade.BackgroundTransparency

if current < fadeGoal then

fade.BackgroundTransparency = math.min(fadeGoal,current+fadeRate)

elseif current > fadeGoal then

fade.BackgroundTransparency = math.max(fadeGoal,current-fadeRate)

else

fade.BackgroundTransparency = fadeGoal

end

end



player = game.Players.LocalPlayer

character = player.Character or player.CharacterAdded:wait()

humanoid = player.Character:WaitForChild("Humanoid")

rs = game:GetService("RunService")



fadeGoal = 1



humanoid.Died:connect(function ()

wait(1)

fadeGoal = 0

player.CharacterAdded:wait()

fadeGoal = 1

end)



rs.RenderStepped:connect(updateFade)



fade.Visible = true
0
Fading to black would require changing BackgroundColor3. Or is it already black? DeceptiveCaster 3761 — 4y
0
on a click? why are u doin some of this extra work couldnt u just use a for loop The_Pr0fessor 595 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
script.Parent.MouseButton1Click:Connect(function()
        if script.Parent.Parent.RebirthFrame.Visible = true the
              script.Parent.Parent.RebirthFrame.Visible == false 
           end
       end)

Here if it works mark it!

0
Don't mind the frame just put the name of the frame for the death GUI name there! vincentthecat1 199 — 4y
0
And yeah why are you wanting it to fade just make it disperse is a button is touched its easier work most games do that. vincentthecat1 199 — 4y
0
i want the frame's transparency to shift smoothly Bylli_Oruze 38 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I hope you already solved this but I guess just in case...all you need is a simple for loop

To achieve this effect, make the ui element black and set its transparency to 1. The for loop will then smoothly make the ui element visible.

local ui = script.Parent
for i = 1,0,-.1 do-- fade to black
    ui.Transparency = i
    wait()
end

to do the opposite(fade away)

local ui = script.Parent
for i = 0,1 do-- fade to black
    ui.Transparency = i
    wait()
end

If you don't understand how for loops work here is some documentation. https://developer.roblox.com/en-us/articles/For-Loops

To connect this to a button

local debounce = false
script.Parent.MouseButton1Click:Connect(function()--script.Parent would be the button
    if debounce == false then
        debounce = true
        --fadeblackelement is whatever the gui element that your wanting to fade is
        local fadeblackelement = script.Parent.Parent.FadeBlack
        if fadeblackelement.Transparency > .5 then 
            for i = fadeblackelement.Transparency ,0,-.1 do--set opaque
                fadeblackelement.Transparency = i
                wait() 
            end
        else
            for i = fadeblackelement.Transparency ,1,.1 do--set transparent
                fadeblackelement.Transparency = i
                wait() 
            end
        end
        debounce = false
    end
end)
0
so would i add the rest of my script under the wait() or do i make a new script for the rest? Bylli_Oruze 38 — 4y
0
I updated my answer to work with a textbutton. If you have any questions, please ask. If this helped please accept the answer. ForeverBrown 356 — 4y

Answer this question