So I made a script that multiplies the button size by 1.1 when you hover over it. BUT, when I continuously hover between multiple ones it kinda shrinks the button. How do I fix this? Here’s my script and demonstration on what happens.
for i,button in pairs(script.Parent:GetDescendants()) do
if button:IsA("TextButton") or button:IsA("ImageButton") then
button.MouseEnter:Connect(function()
script.Parent["ui hover"]:Play()
button:TweenSize(UDim2.new((button.Size.X.Scale * 1.1), (button.Size.X.Offset), (button.Size.Y.Scale * 1.1), (button.Size.Y.Offset)), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.2, true)
end)
button.MouseLeave:Connect(function()
script.Parent["ui hover"]:Play()
button:TweenSize(UDim2.new((button.Size.X.Scale / 1.1), (button.Size.X.Offset), (button.Size.Y.Scale / 1.1), (button.Size.Y.Offset)), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.2, true)
end)
end
end
You are multiplying the current scale by 0.1. You should actually save the original size and use it. Sometimes you may hover while its half tweened and your final size would be 1.5 and not exact.
for i,button in pairs(script.Parent:GetDescendants()) do
if button:IsA("TextButton") or button:IsA("ImageButton") then
local originalSize = button.Size
button.MouseEnter:Connect(function()
script.Parent["ui hover"]:Play()
button:TweenSize(UDim2.new((originalSize.X.Scale * 1.1), (originalSize.X.Offset), (originalSize.Y.Scale * 1.1), originalSize.Y.Offset)), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.2, true)
end)
button.MouseLeave:Connect(function()
script.Parent["ui hover"]:Play()
button:TweenSize(UDim2.new((originalSize.X.Scale / 1.1), (originalSize.X.Offset), (originalSize.Y.Scale / 1.1), (originalSize.Y.Offset)), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.2, true)
end)
end
end