Tweening multiple objects in order?

I have 100 frames (numbered 1-100) that are laid out in a circular shape, and I want to figure out a way to change the color of each going from 1 to 100 within around a half-second to make it look like it’s filling it up, but also I want to change the timing by a few milliseconds sometimes. I’ve tried using RunService, but this won’t work due to it relying on a set speed of 1/60th of a second. Are there any special plugins or possibly a way to manipulate the TweenService to do this? The only way I could really think of, which would be very inefficient, is to set a tween for every single frame to the desired color and increase the tween time by 0.005 of a second each time and switch that by a small amount to get the different timings. But, is there a minimum time for TweenService?

name all the frames from 1 to 100

get frames using GetChildren and sort the table according to their name using the 2nd argument of table.sort
to know about table.sort, scroll down to table.sort:

then loop through the table using for loop and tween and wait for tween to finish

example code:

local frames = parent:GetChildren() -- parent is the parent of the 100 frames

table.sort(frames, function(first, second)
    return tonumber(first.Name) < tonumber(second.Name)
end)

for _, frame in ipairs(frames) do
    local tween = TweenService:Create(frame, ...)
    tween:Play()
    tween.Completed:Wait()
end

edited : change pairs to ipairs

It is important to note that the stateless iterator pairs does not guarantee ordered iteration. What that means is that it iterates over a given table in arbitrary order. In most array cases, it iterates over the array in order. However, this behavior should not be relied upon. Because the order of the table is important (you did just sort it, after all), I encourage you to use ipairs or a numeric for loop.

1 Like

I just did a i=1,100 loop and that seemed to work fine. Thanks

1 Like