How do I size a UI using the original size +5?

  1. This is hard to explain, but I want to make a script that will scale the UI using only it’s original size and a small value, so I can tween all UI’s without having to type out the current size of the UI manually.

  2. The issue is, once I hover over the UI and the UI scales, it lowers it’s original size by like 5 and it never comes back to the original size, and I have no idea why that happens.
    https://gyazo.com/b839d6a14ed870c19026ec879486fe69?token=8c555eab347318a03bd38011aee4af49

  3. I asked my friends and looked on google for solutions, but I didn’t find any.
    https://gyazo.com/e141149d290c0daa23e3392b2006236a

I basically want to be able to scale a UI when I hover over it with the mouse but without having to manually type the size of the UI object, instead just give the UI’s size and add some UDim2 size to it to make it bigger / smaller.


for _,button in pairs(script.Parent:GetDescendants()) do
	if button:IsA("TextButton") then
		local newSize = button.Size + UDim2.new(0,10,0,10)
		local newSize2 = button.Size - UDim2.new(0,10,0,10)
		local newSize3 = button.Parent.Size - UDim2.new(0,10,0,10)
		local newSize4 = button.Parent.Size + UDim2.new(0,10,0,10)
		button.MouseEnter:Connect(function()	
			button:TweenSize(newSize,Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.1,true)
			button.Parent:TweenSize(newSize4,Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.1,true)
		end)	
		button.MouseLeave:Connect(function()
			button:TweenSize(newSize2,Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.1,true)
			button.Parent:TweenSize(newSize3,Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.1,true)
			end)

This is my current script, which is just a snippet of my code but that’s the important part.

You are using different sizes so it will not go to the same size.

if button.Size is 0,10,0,10

newSize is 0,20,0,20
and newSize2 is 0,0,0,0

You should change newSize2 to button.Size, without the extra UDim2.

So you have the base value x, when mouse enters you are doing x + y, when mouse leaves is x - y. So the size will be different, when the mouse leaves, it should have the default value, aka x

Not sure if this is clear so any questions just ask

1 Like

I’ll try that and get back to you with the results

Well looks like you are a genius

TweenSize uses a set value,
when newSize2 is set the size is x, so newSize2 is x - y, let’s say 0,20,0,20 - 0,10,0,10 = 0,10,0,10
newSize is x + y, so 0,20,0,20 + 0,10,0,10 = 0,30,0,30

just remember that after a variable is set, it is no longer button.Size + UDim2(x,x,y,y), it is just a value so it will not change when button.Size is changed

Yeah I never thought that way. I always thought when I do a variable it won’t save the value but instead it will just always check for the current value.

Yeah it can be confusing when you first start out.