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

How to efficiently fade out a ScreenGui without accessing direct elements?

Asked by 4 years ago

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!

0
Use tables, Use GetChildren() function to the screengui and use it in a for i, v loop (use spawn function if needed) yuni_Boy1234 320 — 4y
0
I haven't made the even that triggers this script, you will have to do that, but i think this script can help you fishboy141516 12 — 4y
0
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait() local char = player.Character or player.CharacterAdded:Wait() local frame = script.Parent.Frame local title = GUINAME for i = 1, 0.5, -0.1 do GUIHERE.BackgroundTransparency = i title.Transparency = i wait(0.1) end fishboy141516 12 — 4y
0
You might have to modify it a bit to get it to the way you like it, but i hope it helps :D fishboy141516 12 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

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.

0
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait() local char = player.Character or player.CharacterAdded:Wait() local frame = script.Parent.Frame local title = GUINAME for i = 1, 0.5, -0.1 do GUIHERE.BackgroundTransparency = i title.Transparency = i wait(0.1) end fishboy141516 12 — 4y
0
i was gonna say that idea too, but i never tried, hope it works. Necro_las 412 — 4y
Ad
Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
4 years ago
Edited 4 years ago

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.

Answer this question