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

How do I make a GUI ImageTransparency slowly fade?

So I have this image and I have it slide in and I want it to slowly fade into not visible so I can add other things on the screen, how would I do this? I have a script already attemped I just don't know how It would be done.

local image = script.Parent

if true then
	wait(1.5)
	image:TweenPosition(UDim2.new(0.18, 0, 0.05, 0), 'Out', 'Quart', 3)
else
	while true do
		wait(0.1)
		image.ImageTransparency = image.ImageTransparency - 1
	end
end
	

3 answers

✓ Accepted answer

I think that the easiest solution would be a for loop. Here is a basic example:

for i = .1, 1, .1 do 
	image.ImageTransparency = i -- this is so much simpler than the answer above 
end

You should not do what the answer above tells you. He says to make the decimal amounts smaller that you add to the Transparency to get it to go slower yet he has a wait() that will wait almost no time. The better way to slow a loop is a wait() with a number you like in it instead of smaller and smaller values. So altogether our code should look like this:

for i = .1, 1, .1 do 
	-- you can put a wait here instead it is up to you
	image.ImageTransparency = i 
	wait(.1) -- you can change the wait time to your liking 
end

In your question you subtracted from the Transparency. Transparency means how invisible something is. So if you are subtracting from it what is going to happen? It is going to become less invisible or in normal speech: more visible. That is why either you should add to Transparency or make it change in increasingly larger values. Anyway, Hope I helped and have a great day scripting!

If you have any additional questions or concerns please post them in the comments below.

2 comments

0

I wrote this early in the morning so please forgive any grammar and spelling errors you may find.

0

Yeah, your way is better. I didn't mean to say that if he wanted to make the loop go slower, he should change the "0.01". I meant to say that he could change it to something like "0.05" if he wanted it to go faster.

Another method is using TweenService:

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0) -- parameters: time, easing style, easing direction, repeat count, bool reverses, float delaytime

local tweenTrack = game:GetService("TweenService):Create(image, tweenInfo, {ImageTransparency = 1}) -- parameters: instance your tweening, tweenInfo, goal (has to be in arrays)

tweenTrack:Play() -- play tween track

5 comments

1

This is the best way, and a good habit to build

0

This is the best way, and a good habit to build

local Player = game.Players.LocalPlayer
local Frame = Player.PlayerGui.ScreenGui.Frame

repeat 
    image.ImageTransparency = image.ImageTransparency + 0.01
    wait() 
until image.ImageTransparency == 1

Change the "0.01" if you want it faster. The higher the number, the faster it'll fade. It repeats the loop until the image.ImageTransparency == 1 ,which means fully invisible :)

4 comments

0

Have you ever heard of a for loop?

0

Of course :D

0

Check out my answer for a better way to go about doing this.

0

Thx, that helped me too :D

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