A tween is a chronological operation. If you want to read this code chronologically then your eyes have to jump back and forth. This is bad code design.
Observe the magic number, repeated in multiple places. The code reads in chronological order now but at what cost? We can assign the tweeninfo elsewhere and index its length, but then we’re back to jumping around the document as we read it.
It would be beneficial if you do your research on all Roblox features before asking for one yourself. There’s a 99% chance that it already exists and you don’t know it.
It’s also really easy to test yourself and decide how you want it to behave
I suggested a simple wrapper module; it already gives you :PlayAsync(), and if you need to handle special cases (like duration = 0) you can add that logic yourself
That’s the point of making a wrapper: you can edit the behavior yourself
What they’re saying is that there may be some conflict about timing between
tween:Play()
with a tween time of 0 seconds, and
tween.Completed:Wait()
which would result in an infinite yield.
Indeed the documentation of the Completed event does not specify how it behaves.
So far I have never had any concern about that, and the precised workflow always worked for me. I guess tweeners use a scheduler that will fire Completed, even after an hypothetical delay. The reason why it works may also be completely unrelated of course.
Ooooh I see, my bad. I wasn’t following the full conversation. That is frustrating that it isn’t documented though.
But considering Lua runs on a single thread, and :Play() isn’t asynchronous, and :Wait() seems to consistently fire. I would say it’s safe to bet that Roblox only fires the completed event once the elapsed time is larger than the duration, not equal too it (since its impossible in any duration that’s not 0, so checking is a waste of resources.)
However if I’m wrong and it isn’t consistent then I support this feature request.
The thing is. Why would you need a 0 second tween?
local tweenService = game:GetService("TweenService")
local part = script.Parent
-- Why do this
local uselessTween = tweenService:Create(part, TweenInfo.new(0), {Color = Color3.new(1, 0, 0)})
uselessTween:Play()
-- When you could just do this as it would look exactly the same
part.Color = Color3.new(1, 0, 0)
And here I couldn’t agree more. I guess it would be more of a safety measure in case some formula was used, outputting 0.
I would not create a tween instead of changing a property at all !
If you’re in a situation where you know the tween can have a time of zero, why are you not already creating logic that never creates & plays the tween to begin with? Your example makes no sense when it’s a case that should be solved by the developer, not Roblox.