Hi all, I was wondering a method to effectively fade out a ScreenGui and destroy it completely without accessing each item individually. This includes elements such as TextLabels, ImageLabels, Frames, etc. Here is my current code:
local function FadeGui(ScreenGui) spawn(function() local Transparency = 0 for i = 0, 1, 0.01 do Transparency = i ScreenGui.Backdrop.ImageTransparency = Transparency ScreenGui.Backdrop.CloseButton.ImageTransparency = Transparency ScreenGui.LoadingFrame.DescriptionFrame.BackgroundTransparency = Transparency ScreenGui.LoadingFrame.DescriptionFrame.GameDescriptionFrame.CreatorLabel.TextTransparency = Transparency ScreenGui.LoadingFrame.DescriptionFrame.GameDescriptionFrame.GameLabel.TextTransparency = Transparency ScreenGui.LoadingFrame.ThumbnailFrame.BackgroundTransparency = Transparency ScreenGui.LoadingFrame.ThumbnailFrame.Thumbnail.ImageTransparency = Transparency wait(0.1) end end) end FadeOut(script.Parent)
Any help would be greatly appreciated, thanks!
You cannot fade a ScreenGUI itself as there is a lack of properties, but if you put all of the contents inside of a frame; which could be a holder frame that scales the whole screen, you can just fade that out and it would work fine and give you the result that you are (hopefully) looking for.
Use TweenService
for fading and iterate through all descendants. spawn
is not needed when using TweenService
.
local TweenService = game:GetService("TweenService") local Style = TweenInfo.new(10,Enum.EasingStyle.Linear) --10 seconds local function FadeGui(ScreenGui) for _, element in pairs(ScreenGui:GetDescendants()) do if element:IsA("ImageLabel") then local tween = TweenService:Create(element,Style,{ImageTransparency = 1, BackgroundTransparency = 1}) tween:Play() end if element:IsA("ImageButton") then local tween = TweenService:Create(element,Style,{ImageTransparency = 1, BackgroundTransparency = 1}) tween:Play() end if element:IsA("TextLabel") then local tween = TweenService:Create(element,Style,{BackgroundTransparency = 1, TextTransparency = 1}) tween:Play() end --add more lines if you need to. --add more lines if you need to. end end FadeOut(script.Parent)
Edit: Changed FindFirstChild
that would not work, to :IsA
.