Test if tween has been canceled

I am creating a combo counter for my game and Im having the counter pulse via tweens when you get a combo. I achieve this by modifying the X and Y values for the size offset which makes it grow then shrink by a set amount. The problem is you can get many combos in a quick succession so one tween will start to grow the UI element however the next one will immediately start ending the one that is currently going so it will be unable to shrink back down to its original size. Im wondering if theres a way to test when a tween gets canceled, because .Completed will never fire. Heres an example of my code.

function Gui:Pulse(args)
	local ui = args.Ui
	local duration = args.Duration or 0.5
	local size = args.Size or 50
	local easingStyle = args.EasingStyle or Enum.EasingStyle.Circular
	
	local tinfo = TweenInfo.new(duration/2, easingStyle)
	TweenService:Create(ui, tinfo, {Size = UDim2.new(ui.Size.X.Scale, ui.Size.X.Offset+size, ui.Size.Y.Scale, ui.Size.Y.Offset+size)}):Play()
	task.delay(duration/2, function()
        -- This tween most of the time wont complete due to other ones firing as this plays
		TweenService:Create(ui, tinfo, {Size = UDim2.new(ui.Size.X.Scale, ui.Size.X.Offset-size, ui.Size.Y.Scale, ui.Size.Y.Offset-size)}):Play()
	end)
end

Yes, there is a way.
You will be using the created tween’s PlaybackState to check that.

Here is an example of how to use it:

local TweenService = game:GetService("TweenService")
local Tween = TweenService:Create()
-- ...
if Tween.PlaybackState == Enum.PlaybackState.Cancelled then
	-- ...
end

For your case, you’d probably make a variable/dictionary containing the previous not completed tween(s)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.