Tween all the Childrens of a ScreenGui at the same time

Hi, DevForum Users,
Well, I’m trying to make a function that when user press a key (any), the childrens of the ScreenGui Tween with a fade effect. I’m aware that I can do all this manually like:

But I don’t want a messy code into my scripts, I’m trying to do it with a for loop, like

-- // Not my real code
local function Hide()
    for _, v in pairs(ScreenGui:GetChildren()) do
        if v:IsA('Frame') then
            local X = TweenService:Create(v, TweenInfo, {BackgroundTransparency = 1})
            X:Play()
        elseif v:IsA('TextLabel') then
            local Y = TweenService:Create(v, TweenInfo, {BackgroundTransparency = 1})
            local Z = TweenService:Create(v, TweenInfo, {TextTransparency = 1})
        end
    end
end

But my script doesn’t work, I know maybe I’m not understanding good the for loops. plz help.

Try this

local TWEEN_LENGTH = 0.5 -- seconds it takes to fade out

local function Hide()
	for _, Child in next, ScreenGui:GetChildren() do 
		if Child:IsA("TextLabel") then
			TweenService:Create(Child, TweenInfo.new(TWEEN_LENGTH), {TextTransparency = 1, TextStrokeTransparency = 1}):Play()
		elseif Child:IsA("Frame") then
			TweenService:Create(Child, TweenInfo.new(TWEEN_LENGTH), {BackgroundTransparency = 1}):Play()
		end
	end
end
1 Like

Take a look at this: What is the difference between GetChildren() and GetDescendants()?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.