How to detect when a tween like this is completed

I’m new to Tweening GUIs, how would I detect when a tween is finished for this code?

local circle = script.Parent
local openbutton = script.Parent.Parent.Frame.TweenButton

openbutton.MouseButton1Up:Connect(function()
	--open it/tween it
	circle:TweenSizeAndPosition(
		UDim2.new(0,587,0,587),-- end size
		UDim2.new(0.275, 0,0, 0), -- end pos
		"Out", -- easing direction
		"Quad", -- easing style
		1.5, --time in seconds
		false --override?
	)
end)

I just don’t know how to check for when a tween is completed.

Edit: I didn’t actually need it, but thanks everyone. If you are having this problem, just check the replies.

2 Likes

I don’t think there’s a way to do it for those functions beside just waiting the amount of time the tween lasts, in this case, wait(1.5)

So if I wanted another tween to run 1 second after, I would do wait(2.5)?

I think this is what your looking for, they have a function called

tween.Completed

3 Likes

I’m not sure if that’ll work since they’re used for Tweens created by TweenService, these are tweens made using the Built in tweening functions for GuiObjects

1 Like

What would be the difference? (Between mine and one with TweenService)

local circle = script.Parent
local openbutton = script.Parent.Parent.Frame.TweenButton

openbutton.MouseButton1Up:Connect(function()

         local function OnTweenFinish(state)
          if state == Enum.TweenStatus.Completed then
           --we know that the tween has been competed
          end
         end
	--open it/tween it
	circle:TweenSizeAndPosition(
		UDim2.new(0,587,0,587),-- end size
		UDim2.new(0.275, 0,0, 0), -- end pos
		"Out", -- easing direction
		"Quad", -- easing style
		1.5, --time in seconds
		false --override?
        OnTweenFinish -- you can add functions to the tween here
	)
end)

1 Like

So 0.5 seconds before the first tween ends? That may be an issue if you’re tweening the same thing, since you set Override to false

What do you mean? If the tween lasts 1.5 seconds, and I did, say, 2.5 wait, would it wait 1 second after the tween is done?

Okay I think I had a brain fart and forgot you can set a function to run whe nthe tween is completed, use what @gdgjkjc did

Man I gotta research parameters sometimes

1 Like

Wait doesn’t the GuiObject tweening methods return you a boolean if the tween was completed or not for the parameter of the callback function? If so, shouldn’t it be

local function OnTweenFinish(completed)
	if completed then
	--we know that the tween has been competed
	end
end

For OnTweenFinished?

That’s how they did it in the Article for it

image

In roblox examples in the teaching website they tell you that you should always check the state using Enum.TweenStatus I don’t think It returns a boolean I might be wrong. I think using the boolean technique if (there is one) is bad practice

I’m trying to make this so that a circle goes to nothing, how would I accomplish that?

image
Like this thing’s size goes down to nothing, but still stays in the center.

I think you can post a new topic for that problem

I went on studio and i print the state of the gui and it returns Enum.TweenStatus.Completed I don’t think it returns it as a true or false

That’s odd, I’m not sure why they did it like that for that example then if it returns a TweenStatus, sorry for the misconception!

Here’s another way, At the end, put this:
repeat wait() until circle.Postition == UDim2.new(0.275, 0,0, 0) and circle.Size ==
UDim2.new(0,587,0,587)

Hope this helped someone :smiley:

I’m actually dumb and I just realized I could resize the thing. (Thanks anyways @EmbatTheHybrid, @gdgjkjc, @Dan_foodz, @VoidException)

So basically this is solved with no solution.

Now what I need help on is my other problem, thanks!

Try callback after override

local function callbackName()
      -- tells you if the tween is completed
end

openbutton.MouseButton1Up:Connect(function()
	--open it/tween it
	circle:TweenSizeAndPosition(
		UDim2.new(0,587,0,587),-- end size
		UDim2.new(0.275, 0,0, 0), -- end pos
		"Out", -- easing direction
		"Quad", -- easing style
		1.5, --time in seconds
		false --override?
        callbackName -- the call back
	)
end)