Help with math for a fading GUI

Hello I am new to this but I will try to keep it simple and clear what I am trying to make is a function that fades a gui object and in a provided amount of time so if I entered for example :

ModuleScript:Disappear(BGframe,2)--time and selected frame

now everything else is done making it disappear but revert to its normal transparency and all that jazz that is not what I am here for
I am here cause when I put bigger numbers as the time the fading is choppy
I am looking for a loop function that will take the time and the bigger it is the less of the transparency it will add on each full loop

please help also sorry for the broken English (if it is) and please tell me if I need to describe this more this is my first ever post on the forum

Most likely because you’re doing it in a for or while loop. I’d recommend you look into tweenservice! No messing with loops required.


I wouldn’t recommend using loops when you have TweenService. It is generally better to use the Roblox API and events over loops for things like this. TweenService allows you to move objects and change object values smoothly in a given time. The script below is a little example of how you could use TweenService to do what you are trying to do:

local TweenService = game:GetService("TweenService")

local module = {}

function module:Disappear(Object, Time)
	local tweenInfo = -- Creates the TweenInfo
		Time, -- The time the tween takes
		0, -- How many times you want it to repeat?
		false, -- Do you want it to reverse?
	local Tween = TweenService:Create(Object, tweenInfo, {Transparency = 1}) -- Creates the tween. At the end of the tween the transparency of the object will be 1.
	Tween:Play() -- Plays the tween
	Tween.Completed:Connect(function() -- Fires when the tween completes
		-- What do you want to do when the tween completes?

return module


thank you both guys for the help now i see the mistake in my approch :sweat_smile: