Help with TweenService again

I am using TweenService to tween a gui and I notice that if I spam click to play the Tween both tweens will overwrite. Currently I don’t know how to fix it so where one tween plays at a time. Any help thanks.

1 Like

Have you tried checking if any of the tweens are playing prior to triggering another tween?

How do you check if one of the tweens is in progress?

Maybe try adding a debounce with the text button. It should prevent players from spamming the button and give time for the tween to play out

So for the debounce I make it as long as the tween?

Yes. It will give time for the tween to play and not overlap

You can use Tween.Completed to wait:

local db = false
local tween = --define here
local TextButton = -- define here
TextButton.Activated:Connect(function()
     if db == false then 
        db = true
        tween:Play()
        tween.Completed:Wait()
        db = false
     end
end)

It isn’t working is there anything wrong with my code?

script.Parent.MouseButton1Click:Connect(function(player)
if db == false then
db = true
forthtween:Play()
forthtween.Completed:Wait()
backtween:Play()
db = false
end
end)

Instead of using TweenService for GUI, use GuiObject:TweenSize OR GuiObject:TweenPosition. These functions have an override argument which you can set as false which will prevent animations from overriding.

How do I set the argument to false

If you read the docs it there should be all the parameters required. But, I will show an example:

textButton:TweenPosition(UDim2.new(1,1,1,1),Enum.EasingDirection.Out,Enum.EasingStyle.Cubic,1,false)

FirstParameter: The End position in UDim2
SecondParameter: The easing direction (which direction the gui should tween to In, Our or InOut)
ThirdParameter: The easing style (The animation type Linear, Cubic, Bounce )
FourthParameter: The time it takes to finish the animation in seconds
FifthParameter: Whether this animation should override other playing animations

I read the document but how do I use them to run 1 tween then another without overwriting

I think what your trying to do is only play one tween at a time. To do this you can check the tween PlaybackState. This will check what the tween is doing. (ex: if tween1.PlaybackState ~= Enum.PlaybackState.Playing then tween2:Play())