GetChildren in TweenInfo

Hello there,

I am trying to write a script where the tweeninfo will get all the children of a Frame and tween the TextLabel’s transparency to give it a fade in and out effect. For some reason, the script runs, but it only tweens the first TextLabel within the frame.

local LoadingTime = script.Parent
local LoadingTimeChildren = LoadingTime:GetChildren()


local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)



LoadingTime.Visible = true

for numberof, textlable in pairs(LoadingTimeChildren) do
	
	if textlable:IsA("TextLabel") then
		local LoadingTimeTween = tweenservice:Create(LoadingTime.TextLabel, tweeninfo, {TextTransparency = 1})
		LoadingTimeTween:Play()

	end
	
end

I recommend using CanvasGroup, as it saves you a massive headache when trying to tween all descendants for fade out effects.

What you do is switch the Loading Time Frame to a CanvasGroup and then tween the CanvasGroup.GroupTranparency.

Canvas Group is another form of frame?

Pretty much, but it allows you to change the Transparency and Color of all the descendants at once. It is very convenient for tweening.


On a separate note, after reviewing your code. It seems the issue is that you are using “pairs” instead of “ipairs”.

I see. Will give it a try. I changed it to in ipairs but it still provided the same results.

Okay, the issue is this line. It should be:

`local LoadingTimeTween = tweenservice:Create(textlabel, tweeninfo, {TextTransparency = 1})`

Quite funny…now It only tweens the second Text Lable.

You have the first argument of tweenesrvice:Create() as LoadingTime.TextLabel. It will randomly pick one and tween that same one every time. You want to use the textlabel that is given in the for loop.

Ah yes! It worked. You learn something new everyday!

1 Like

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