Hi y'all! I've been working on this piece of code that will slowly fade a given UI's transparency. I'm just wondering if there is anything I can do to improve it. Any help or tips would be greatly appreciated.
local Bindable_Function = script:WaitForChild("Fade_Function")
function Fade(UI, Fade_Speed, Fade_To)
-- Check if it is a Frame
if UI:IsA("Frame") then
if Fade_To < UI.Transparency then
while UI.Transparency >= Fade_To do
UI.Transparency -= Fade_Speed
wait(0.01)
end
else
while UI.Transparency <= Fade_To do
UI.Transparency += Fade_Speed
wait(0.01)
end
end
end
-- Check if it is an Image
if UI:IsA("ImageLabel") then
if Fade_To < UI.ImageTransparency then
while UI.ImageTransparency >= Fade_To do
UI.ImageTransparency -= Fade_Speed
wait(0.01)
end
else
while UI.ImageTransparency <= Fade_To do
UI.ImageTransparency += Fade_Speed
wait(0.01)
end
end
end
-- Check if it is a text label or button
if UI:IsA("TextLabel") or UI:IsA("TextButton") then
if Fade_To < UI.TextTransparency then
while UI.TextTransparency >= Fade_To do
UI.TextTransparency -= Fade_Speed
wait(0.01)
end
else
while UI.TextTransparency <= Fade_To do
UI.TextTransparency += Fade_Speed
wait(0.01)
end
end
end
end
local function Fade_UI(UI, Fade_Speed, Fade_To, Fade_Children, Fade_Parent)
-- Check if we want to fade the given UI
if Fade_Parent then
coroutine.wrap(Fade)(UI, Fade_Speed, Fade_To)
end
-- Check if we want to fade the children
if Fade_Children == true then
for _, child in UI:GetChildren() do
coroutine.wrap(Fade)(child, Fade_Speed, Fade_To)
end
end
end
Bindable_Function.OnInvoke = Fade_UI

1 comment
Does it work?