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

How can i make a "fade" animation for my gui without having to wait for every single frame in it?

Asked by
1lO_Ql1 -1
4 years ago

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.

0
do a loop? TheRealPotatoChips 793 — 4y

Answer this question