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

How do you fade an ImageLabel?

Asked by 5 years ago

I'm really out of options and I'm a beginner as well so I don't have that much knowledge of how. I kept trying ImageTransperency and other methods but they don't keep working. I know that this is a website to help scripters and such, but I would really like it if you could teach me into how.

2 answers

Log in to vote
0
Answered by
Avi_i 2
5 years ago

I'm going to assume you want it to Fade away so this is how you would do that.

TextLabel = DEFINEVARIABLEHERE
for i = 0, 1, .1 do
     TextLabel.Transparency = i
end
TextLabel.Visible = false

Maybe thats a little to quick for you, so what we can do here is add a little wait()

TextLabel = DEFINEVARIABLEHERE
for i = 0, 1, .1 do
     wait(.05)--Change number to whatever makes you comfortable
     TextLabel.Transparency = i
end
TextLabel.Visible = false

Make sure to define the "TextLabel" variable, if you don't know how to then DefiningVariables

Ad
Log in to vote
0
Answered by 5 years ago

To fade an ImageLabel, you have a lot of options, really. The most "intuitive" for a beginner being: define a loop that would increase the ImageLabel's transparency over time. Like so:

for i=1, 100 do
    ImageLabel.ImageTransparency = ImageLabel.Transparency + 1/100
    wait()
end

This makes the image fade. However, the fading is a bit arbitrary here, so what we could do is define some parameters:

  1. fadeTime - how long it would take to fade
  2. smoothness - how "smooth" the fading would be
local fadeTime = 1 -- seconds
local smoothness = 100 -- how many times the loop would run

for i=1, smoothness do
    ImageLabel.ImageTransparency = ImageLabel.ImageTransparency + fadeTime/smoothness
    wait(fadeTime/smoothness)
end

Alright, that's a bit smoother. But we could go further. Using the RunService, we could create a fading effect that matches the player's FPS. We do this by connecting to the RenderStepped event, getting the amount of time that has passed, then dividing that by the fadeTime and adding it to the transparency.

local fadeTime = 1
local connection -- to store the connection to renderstepped()

connection = RunService.RenderStepped:Connect(function(delta)
    ImageLabel.ImageTransparency = ImageLabel.Transparency + (delta/fadeTime)
    if ImageLabel.ImageTransparency >=1 then
        ImageLabel.ImageTransparency = 1
        connection:Disconnect()
    end
end)

Woah there, that looks a bit complicated for someone just starting out. A better alternative would be to use the TweenService. You could learn how to do that here. But in a nutshell:

  1. Create a Tween object for your ImageLabel, with the properly set TweenInfo.
  2. Do Tween:Play().

Oh, if you wanted the entire ImageLabel to disappear, just add to the BackgroundTransparency of the ImageLabel along with the ImageTransparency.

Hope that helps!

0
I tried entering this script but it doesn't work, probably I have it wrong. Do I insert a Frame and then the ImageLabel into the Frame or do i just insert the ImageLabel by itself. Also do I use a regular Script or a LocalScript? ninjabloodman -22 — 5y
0
If you're just copy/pasting the code snippets, you're doing it wrong. I only put them there as examples for you to learn from them. Aniline_Purple 266 — 5y
0
Also, you'd have to use a LocalScript. Aniline_Purple 266 — 5y

Answer this question