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

Fade frame transparency on TextButton click?

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

2 comments

0

Fading to black would require changing BackgroundColor3. Or is it already black?

0

on a click? why are u doin some of this extra work couldnt u just use a for loop

2 answers

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!

3 comments

0

Don't mind the frame just put the name of the frame for the death GUI name there!

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.

0

i want the frame's transparency to shift smoothly

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)

2 comments

0

so would i add the rest of my script under the wait() or do i make a new script for the rest?

0

I updated my answer to work with a textbutton. If you have any questions, please ask. If this helped please accept the answer.

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