Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there any function to check if a tween was completed or not?

I have this script that tweens the textbutton's size to look like it expanded:

script.Parent.MouseEnter:Connect(function()
    script.Parent:TweenSize(UDim2.new(0,250,0,100),"Out", "Bounce")
end)
script.Parent.MouseLeave:Connect(function()
    script.Parent:TweenSize(UDim2.new(0,200,0,50),"Out", "Bounce")
end)

The problem is, if the mouse leaves before the MouseEnter event finishes, the textbutton remains expanded, even though the mouse left. So I thought I should check if a tween was finished or not, but I don't know what function does that.

3 answers

✓ Accepted answer

You could use the override parameter of :TweenSize

script.Parent.MouseEnter:Connect(function()
	script.Parent:TweenSize(UDim2.new(0,250,0,100), "Out", "Bounce", 1, true) -- true means override other tweens that are currently playing
end)

script.Parent.MouseLeave:Connect(function()
	script.Parent:TweenSize(UDim2.new(0,200,0,50), "Out", "Bounce", 1, true)
end)

1 comment

0

Yes, this worked! Thank you!

I would just do if script.Parent.Size == UDim2.new(0,200,0,50) then

not sure if this will actually work, haven't tested it

5 comments

0

Ok, lemme try it...

0

Nope, didn't work.

0

Did you get an error?

0

No.

0

Huh, I'm sorry but i dont really know what else would work

Hmm.. I do not think there's a function that Roblox has created for that need. But I recommend just check if the requested Position/Size has been reached. For example :

local Frame = script.Parent.Parent
local Button = script.Parent

Button.MouseButton1Click:Connnect(function()
   Frame:TweenPosition(
       UDim2.new(12.3, 53, 50),
       "Out",
        "Quint",
         3
end)

if Frame.Position ~= Vector3.new(12.3, 53, 50) then --Checks if the position is not the end position.
   game.Players.LocalPlayer.PlayerGui.Intro.PlayButton.Visible = false
 elseif Frame.Position == Vector3.new(12.3, 53, 50) then --Checks if the position is the end position
   game.Players.LocalPlayer.PlayerGui.Intro.PlayButton.Visible = true
end

This example prevents a button to be visible until it detects that the position of a Frame has arrived to the requested end position 12.3, 53, 50, if it is so it will make a button visible and else it will not make the button visible. I really hope this helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.