TweenSize scaling down ImageButton more than expected

Hi, recently I have made a script that scales down an ImageButton when the players cursor is hovered over it. It works, but for some reason it scales down as much as possible; to the point where you cannot see it. Here is the code that I made.

local button = script.Parent

local hover = Workspace.Hover

local selectsound = Workspace.select

button.MouseEnter:Connect(function()

hover:Play()

script.Parent:TweenSize(UDim2.new(0, -0.01, 0, 0), "Out", "Linear", 0.4)

end)

button.MouseButton1Click:Connect(function()

selectsound:Play()

end)

If anyone can help, it would be a help! :smiley:

you have to set the tween size to the actual size that you want the button to be, not how much smaller you want it

im so dumb lol, thank you very much!

local button = script.Parent
local buttonSize = button.Size

local hover = workspace:WaitForChild("Hover")
local selectsound = workspace:WaitForChild("select")

button.MouseEnter:Connect(function()
	hover:Play()
	button:TweenSize(buttonSize - UDim2.new(0.1, 0, 0, 0), "Out", "Linear", 0.4)
end)

button.MouseLeave:Connect(function()
	button:TweenSize(buttonSize, "In", "Linear", 0.4)
end)

button.MouseButton1Click:Connect(function()
	selectsound:Play()
end)

You can’t reference “Workspace” like that, it has to either be game.Workspace or workspace, the capitalisation is important. It is also possible to change size by subtracting a UDim2 value from the current UDim2 value assigned to the “Size” property of the TextButton instance. I’ve also added a MouseLeave event which plays the inverse of the tween (reverts TextButton instance back to default position).

1 Like

Thank you for the tip! New to scripting, so helps alot! :wink: