Mouse hovering on GUI problem

Hello.
I try to make a GUI button that increases it’s size every time the mouse hovers on it, and goes back to normal when the mouse is not hovering on it.
local object = script.Parent

script.Parent.Parent.MouseEnter:Connect(function()    
    object:TweenSize(UDim2.new(0, 130, 0, 130), nil, nil, 0.1)
    object.Parent:TweenSize(UDim2.new(0, 158, 0, 149), nil, nil, 0.1)
end)

script.Parent.Parent.MouseLeave:Connect(function()
    object:TweenSize(UDim2.new(0, 116, 0, 116), nil, nil, 0.1)
    object.Parent:TweenSize(UDim2.new(0, 144, 0, 135), nil, nil, 0.1)
end)

But when the player hovers the mouse on the GUI button for less than a 0.1 second, the GUI is stuck as 130,130 and 158,149 until the player hovers again.

There is another parameter, a fifth one called override. This determines if the tween is able to be overridden by another one mid tween. Set it to true to fix this.

You should just use TweenService though, as it can do everything these methods can do and more. Overriding is also implicit (done automatically). I imagine these Gui tween methods going to get deprecated in the future sometime.

2 Likes