Efficient way to run a loop while a tween is running?

Alright, so I’m a little braindead right now.

I’ve created a tween with TweenService that animates a UI element’s position, and I need additional functionality to flash the visibility of it as long as the tween is running.

I figured I could do this at first glance:

while tween.Completed:Wait() do
--//flash stuff here
end

However, I realize I’m braindead and by doing that, it’ll yield until the .Completed event fires…

I’m trying to find the most efficient way of yielding my loop so it doesn’t crash the game, as long as tween is running, I could do .Stepped:Wait() using Run Service, but I wondered if there’s a more efficient way.

Thanks :slight_smile:

Tweens have a PlaybackState property. I am pretty sure you can do

while tween.PlaybackState ~= Enum.PlaybackState.Completed do

end

This loop will run as long as it doesn’t complete.

2 Likes

That works, but I was wondering about what way would be ideal to yield the loop so it doesn’t crash the server.

I guess a .Stepped:Wait() would work?

For however long you want, bud. That is up to you to decide.