How can i make a "fade" animation for my gui without having to wait for every single frame in it? here's my current code:

---------------------------------main script
gui = script.Parent
local ok = require(gui.MAINMOD)
	ok:FadeOut(gui.loader)
	for _,c in pairs(gui.loader:GetDescendants())do
		if c.Name~="LocalScript"then
	ok:FadeOut(c)
	end
	end
	ok:swait(3)
	gui.loader:Destroy()
	gui.main.Visible = true
	ok:FadeIn(gui.main)
	for _,c in pairs(gui.main:GetDescendants())do
	ok:FadeIn(c)
	end
-------------------- Module script
local module = {}
ArtificialHB = Instance.new("BindableEvent", script)
ArtificialHB.Name = "ArtificialHB"

script:WaitForChild("ArtificialHB")
Frame_Speed = 1 / 60
frame = Frame_Speed
tf = 0
allowframeloss = false
tossremainder = false
lastframe = tick()
script.ArtificialHB:Fire()

game:GetService("RunService").Heartbeat:connect(function(s, p)
	tf = tf + s
	if tf >= frame then
		if allowframeloss then
			script.ArtificialHB:Fire()
			lastframe = tick()
		else
			for i = 1, math.floor(tf / frame) do
				script.ArtificialHB:Fire()
			end
		lastframe = tick()
		end
		if tossremainder then
			tf = 0
		else
			tf = tf - frame * math.floor(tf / frame)
		end
	end
end)
function module:swait(num)
if num == 0 or num == nil then
		ArtificialHB.Event:wait()
	else
		for i = 1, num do
			ArtificialHB.Event:wait()
		end
	end
end
function module:FadeOut(gui)
if gui:IsA("TextLabel") or gui:IsA("TextBox") or gui:IsA("TextButton") then
 for i = 1,100 do 
gui.TextTransparency = gui.TextTransparency + 0.01 
module:swait()
end 
end 
for i = 1,100 do
 gui.BackgroundTransparency = gui.BackgroundTransparency + 0.01
 module:swait()
end 
end
function module:FadeIn(gui)
if gui:IsA("TextLabel") or gui:IsA("TextBox") or gui:IsA("TextButton") then 
for i = 1,100 do gui.TextTransparency = gui.TextTransparency - 0.01
 module:swait()
end 
end
 for i = 1,100 do
 gui.BackgroundTransparency = gui.BackgroundTransparency - 0.01 
module:swait()
end 
end
return module

This code will wait for every gui part instead of doing it all together. I would like it to do the fade animation all together but I don't know how.

1 comment

0

do a loop?