Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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!

4 comments

0

Use tables, Use GetChildren() function to the screengui and use it in a for i, v loop (use spawn function if needed)

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

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

0

You might have to modify it a bit to get it to the way you like it, but i hope it helps :D

2 answers

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.

2 comments

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

0

i was gonna say that idea too, but i never tried, hope it works.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.