Hi, today I want to make a GUI that has tweens, but it has a lot of texts and I don’t want to make the tweens one by one, if you didn’t understand what I want to do, here is an example:
Let’s say I have a TweenInfo and a Goal, and when I do TweenService:Create(part), I want the same values of TweenInfo and the Goal to be applied to the box where I put part.
And that’s what I want to do, tweet multiple parts with the same value of TweenInfo and Goal, thank you for helping me!
I want answers related to this topic. Sorry, I’m bad explaining. If you need more information, don’t hesitate to leave it in the answers and I’ll answer you!
for i,v in pairs(Texts:GetChildren()) do
spawn(function()
game:GetService("TweenService"):Create(v, TweeInfo.new(1)--[[amount of time--]], {Position = UDim2.new(0,0,0,0--[[Position here]]}):Play()
end)
end
Please don’t use spawn. It’s not necessary either as you are able to call tweens asynchronously. Also, GetChildren returns an array, so use ipairs instead.
That wouldn’t work, If you change the Parent backgroundtransparency of a frame, but its the parent, it still wouldn’t change the descendants backgroundtransparency
Given that your aim here is to tween over multiple Gui elements at one time, you will be required to iterate over the set of elements you’re looking to transition, create an individual tween for it and then run it, like igna’s code sample shows.
TweenService is only intended to facilitate transitions on a single object. You can create a function that hides away the fact that you’re doing this but ultimately there’s no point in doing that. There’s nothing wrong with creating multiple tweens so I’m not sure why you wouldn’t want to unless you’re concerned about readability which will not be affected in this scenario.
There’s one technical exception I can think of where you can tween multiple objects at once and that’s if you want to tween a model. I wrote a tutorial that covers smartly using welds in order to effectively tween multiple parts when you actually only tween model. If you’re interested.
There’s a way you could sync up all other TextLabels to a central value, tween that value and then set the TextTransparency of the rest of the labels, but I wouldn’t recommend it. I don’t believe Changed will fire fast enough to catch all intermediate frames of the tween.
Oh hey, could you easily explain different between ipairs and pairs? I never got it right, i’ve seen some tutorials, the most are in english and I speak spanish so kinda difficult? can you just really easy explain difference between ipairs and pairs? thanks so
There’s a few members in the community who write frequent posts about the difference so at the very least I’d be able to summarise what the deal is for you.
Essentially, you have what we call an array and a dictionary for tables.
local array = {1, 2, 3}
local dictionary = {
["A"] = true,
["B"] = true,
}
pairs:
Meant to go through tables where you set both a key and a value
Traversal (going through the table) does not have an order
ipairs:
Meant to go only through tables where you have elements
Traversal is guaranteed to be in order
ipairs is faster than pairs because the generator knows what the next key is and what order to run through the table in. Their use has also sometimes been the defining difference between whether something works properly or not. Use of ipairs also helps tell exactly what you’re iterating over.