How to tween multiple things?

Yeah so I made this tween and I was expecting that when the function is called every TextButton should Tween its BackgroundTransparency and the TextTransparency of a TextLabel in the Button at the same Time. But the Button don’t tween at the same time and they don’t even tween the TextTransparency of the parented textlabel. My Question: How to fix this script that every Tween plays at the same time (basically how to play multiple tweens at the same time).

function Visible()
	for i,v in pairs(script.Parent.Options:GetChildren()) do
		if v:IsA("TextButton") and v.TextLabel then
			if v.BackgroundTransparency == 1 then
				local Tween = TweenService:Create(v, TweenInfo.new(1.5), {BackgroundTransparency = 0}, v.TextLabel, TweenInfo.new(1.5), {TextTransparency = 0})
				Tween:Play()
				Tween.Completed:Wait()
			else
				local Tween = TweenService:Create(v, TweenInfo.new(1.5), {BackgroundTransparency = 1}, v.TextLabel, TweenInfo.new(1.5), {TextTransparency = 1})
				Tween:Play()
				Tween.Completed:Wait()
			end	
		end
	end
end

use coroutine.wrap function…
this basically makes the script play not having to wait until something finishes.

1 Like

Sorry never got my hands on that function before :confused:
could you help me making this work with this function? should i add
coroutine.warp:connect(function()
–stuff
end)
?

Sorry for the late reply, I was busy
you should do this

coroutine.warp(function()

end)()

Sorry if I can’t explain a lot It’s kinda hard to explain
This should help you.
https://developer.roblox.com/en-us/api-reference/lua-docs/coroutine

1 Like

Hi, I made a script for tween using coroutine.warp
Hopefully this should help you understand abit more.

local TweenService = game:GetService("TweenService")


local Part1 = game.Workspace.Part1
local Part2 = game.Workspace.Part2


local Tween1 = TweenService:Create(Part1, TweenInfo.new(), {Transparency = 1})
local Tween2 = TweenService:Create(Part2, TweenInfo.new(), {Transparency = 1})

coroutine.wrap(function()
	Tween1:Play()
end)()
Tween2:Play()
2 Likes

The expected behavior should be that both tweens play at the same time?

Oh and if I add like 2 more tweens that should happen at the same time too. SHOULD I just add the function, down below the coroutine function?

I don’t see why you need to make a coroutine? On default, tweens don’t yield unless you do

Tween.Completed:Wait()

Another thing to note here is that you can actually tween multiple properties with a single constructor.

local TWS = game:GetService("TweenService")

local part = workspace.Part1
local tween = TWS:Create(part, TweenInfo.new(2), {Transparency = 1, Size = part.Size + Vector3.new(10, 10, 10), Reflectance = 1})

tween:Play()

Yeah i tried to do that, because there is a button in the button which should tween its text transparency :confused:
Im not sure how to do the same thing but EVERYTHING (button, button in button,etc.) tweens at the same time. Should I just remove the .Completed:Wait() thing?

1 Like

Do you want to look for descendants (all the children of a child)? If so, you can just use :GetDescendants() instead of :GetChildren().

1 Like

Oh forgot about that. I will try this out!

Yep I tried it and now it works perfectly! Tysm!