So a lot of games have it when you hover over a button it gets bigger. I have an issue when you enter and leave the button fast the button magnifies and never unmagnifies.
My question is (to make it more clear), how would I make it so when you hover it dosent do this?
I think its because of the TIME it takes for it to tween
There is a parameter after the time parameter in the TweenSize() function called override. If you set that to true for both tweens, it’ll override the currently playing tween, which should fix the issue.
When the mouse leaves the button, if the tween is still playing, it needs to cancel the previous tween before it can play the ‘shrink’ tween. This also is the case vise-versa, meaning it needs to cancel the ‘shrink’ tween before it can play the ‘grow’ tween. The issue is, there is no way (that I am aware of) to cancel a TweenSize() function. Instead you will have to use the Tween Service and make a custom Tween that changes the size. Here is an example with the tween cancellation added:
local sound = game.ReplicatedStorage.OtherSounds.MouseEnter_Leave
local tweenService = game:GetService("TweenService")
local object = script.Parent
local GrowTween = TweenService:Create(object, TweenInfo.new(
0.5,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut),
{Size = UDim2.new(0,210,0,60)}
)
local ShrinkTween = TweenService:Create(object, TweenInfo.new(
0.5,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut),
{Size = UDim2.new(0,200,0,50)}
)
script.Parent.MouseEnter:Connect(function()
sound:Play()
GrowTween:Cancel()
ShrinkTween:Cancel()
GrowTween:Play()
end)
script.Parent.MouseLeave:Connect(function()
GrowTween:Cancel()
ShrinkTween:Cancel()
ShrinkTween:Play()
end)
Try this, hopefully it works otherwise you may need to instantiate the tween each time. Good luck!
Edit: In the time writing this, @pwnion suggested using the override argument, which I was unaware of but may be easier and efficient.