Check If A Tween Has Finished

Hello! So, I was making a Hover & Tween Text Label then I found out, when you tween some text flat, you can still see the text.

Screen Shot 2020-07-10 at 9.36.07 pm

How can I check if the tween finished so I can make the Text Label invisible or is there some other way to solve this?

Note: The parameter, override is set to true.

You can use tweenservice and use Completed:

local TS = game:GetService("TweenService") -- Gets the service
local TI = TweenInfo.new(Time, EasingStyle, EasingDirection) -- Easing Information

local Tween = TS:Create(TextLabel, TI, {Size = SizeHere}) -- Crerates the tween
Tween:Play() -- Plays the tween
Tween.Completed:Wait() -- Waits for the tween to finish
TextLabel.BackgroundTransparency = 1 -- Sets the transparency to 1

I’m guessing you were using TweenSize, which you shouldn’t because it is deprecated(no more updates coming to it).

2 Likes

If you are using the :TweenPosition method then you can use the last argument, a function, that will be called when the tween finishes:

https://developer.roblox.com/en-us/api-reference/function/GuiObject/TweenPosition

May I have an example of callback?

gui_object:TweenPosition(
	UDim2.new(), -- go back to corner
	Enum.EasingDirection.In, -- direction
	Enum.EasingStyle.Sine,   -- style
	2, -- how long it lasts
	true, -- override
	function()
        print("tween completed/interrupted")
    end
)
1 Like

So, does the function run when the tween is completed or do I have to check?

It’s a callback, it’s similar to :Connect()ing to a script signal. It will run by itself when the tween is finished.

Edit: or when the tween is interrupted. Which happens will be passed to the callback as a enum

1 Like

The argument passed to the callback is a Enum.TweenStatus:

image

From there just check if it was cancelled or completed

1 Like