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

Is there a way to fix this GUI fade effect?

I'm making a basic intro to my place with a fading GUI when the player joins.

The GUI is supposed to have to delay before it starts fading away. That's what the wait(3) is for.

The problem is the GUI will wait 3 seconds before fading again. Like after 3 seconds the GUI will fade by +0.1. Then after another 3 seconds, the GUI will fade by +0.1 again until the GUI is gone.

I know there is a way to fix it but I don't know that much scripting to know how to fix it. I hope you can understand what problem I'm talking about.

I thought of something like stopping the script of doing wait(3) again but I don't know.

GUI = script.Parent

for i=1,10 do
	wait(3)
		GUI.BackgroundTransparency = GUI.BackgroundTransparency + 0.1
	end

1 comment

0

Remove the wait(3) from line 4 and place it on line 2

2 answers

✓ Accepted answer

This is because you put the wait(3) inside the for loop. This means it's going to wait 3 seconds for every iteration of the loop. If you want to wait 3 seconds before fading it, simply put the wait(3) before the for loop.

Remember to also put a wait() inside of the for loop, with however long you want between each frame of the fading.

Also, you can make your for loop from 0, to 1 with increments of 0.1 instead of adding 0.1 to the transparency every time.

Here's an example:

local GUI = script.Parent

wait(3) -- wait 3 seconds before fade

-- now we fade out
for i = 0, 1, 0.1 do -- go from 0 to 1, increasing by 0.1 every iteration
	GUI.BackgroundTransparency = i -- set the transparency to i
	wait(.1) -- wait a small amount of time between each frame
end

Hope this helps! :)

You can create an easier way for fading using TweenService! Trust me and give yourself a chance to learn it!

WIKI: https://wiki.roblox.com/index.php?title=API:Class/TweenService

Script:

-- Fading
-- Local Script

local TweenService = game:GetService("TweenService")

local GUI = script.Parent

local Time = TweenInfo.new(1) -- Time to Fade out

local Goal = {}
Goal.BackgroundTransparency = 1

local Tween = TweenService:Create(GUI, Time, Goal) -- Creates Tween


wait(3) -- Waiting 3 seconds before fade

Tween:Play() 

This method is much easier and better! Hope that I helped!

2 comments

0

Its easier using for loops, but acceptable

0

That's an opinon. Some people may find other things easier. Just saying. ;)

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