Mouse hover change button size too much

Hello devs!

I have a problem when the player starts hovering over the button several times, then it will shrink and shrink.
This is how it looks (sorry for audio):

here is script:

local gui = script.Parent

local tInfo = TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

local function on_Hover(frame)
	TweenService:Create(frame, tInfo, {Size = UDim2.new(frame.Size.X.Scale * 1.25, 0, frame.Size.Y.Scale * 1.25, 0)}):Play()
	
end

local function not_Hover(frame)
	TweenService:Create(frame, tInfo, {Size = UDim2.new(frame.Size.X.Scale / 1.25, 0, frame.Size.Y.Scale / 1.25, 0)}):Play()
end

for i, button in pairs(gui:GetDescendants()) do
	if button:IsA("TextButton") then
		button.MouseEnter:Connect(function()
			on_Hover(button)
		end)
		button.MouseLeave:Connect(function()
			not_Hover(button)
		end)
	end
end
1 Like

I believe it’s just best for you to store a constant of the initial size, and then tween back to that size when your mouse leaves:

local gui = script.Parent

local tInfo = TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

local ButtonDefaults = {} -- Table of the default sizes

local function on_Hover(frame)
	TweenService:Create(frame, tInfo, {
        Size = UDim2.fromScale(
            ButtonDefaults[frame.Name].X.Scale * 1.25,
            ButtonDefaults[frame.Name].Y.Scale * 1.25
        ) -- Set the size to the default size * 1.25 (or any amount!)
    }):Play()
end

local function not_Hover(frame)
	TweenService:Create(frame, tInfo, {Size = ButtonDefaults[frame.Name]}):Play() -- Reset the size to the default
end

for i, button in pairs(gui:GetDescendants()) do
	if button:IsA("TextButton") then
        ButtonDefaults[button.Name] = button.Size -- Add the original size to the table
		button.MouseEnter:Connect(function()
			on_Hover(button)
		end)
		button.MouseLeave:Connect(function()
			not_Hover(button)
		end)
	end
end

Hope this helps you out a bit, let me know of any concerns!

3 Likes

im sorry but how do you make the rest of the buttons move so it wouldnt overlap? i have an issue with it