How to increase OffSet size?

Hi, i’m making a button that changes size in and out when you hover over it.

I don’t rly know about Size.X.Offset and using + to increase the size of the gui button.
It’s familiar to a button that tweens (If you clicked it down, it pushes down. Then if you then let go, it pushes straight up )

script.Parent.MouseEnter:Connect(function()
	for i = 3,50 do
		script.Parent.Size = script.Parent.Size.X.Offset + UDim2.new(0,20,0,0)
		script.Parent.Size = script.Parent.Size.Y.Offset + UDim2.new(0,20,0,0)
		wait()
		end
	end)
1 Like

You should use the TweenSize function or the TweenService, your script should look like this:

script.Parent.MouseEnter:Connect(function()
    script.Parent:TweenSize(UDim2.fromOffset(script.Parent.Size.X.Offset + 20, script.Parent.Size.Y.Offset + 20), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 1)
end)

Hello there. Not really sure what the for loop is for, but I think this little fix would fix your code and make it resize smoother:

script.Parent.MouseEnter:Connect(function()
	script.Parent:TweenSize(UDim2.new(0, 20 + script.Parent.Size.X.Offset, 0, script.Parent.Size.Y.Offset), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 0.5)
end)
1 Like

@Batman212369 I come too late, of course, but I recommend to use UDim2.fromOffset, because it makes the script shorter. Otherwise I agree with you.
@Da_RealHonestmam Your current code does not work because you add 0 to the Y size. It should look like this:


script.Parent.MouseEnter:Connect(function()
	for i = 3,50 do
		script.Parent.Size = script.Parent.Size.X.Offset + UDim2.new(0,20,0,0)
		script.Parent.Size = script.Parent.Size.Y.Offset + UDim2.new(0,0,0,20) --Here is the place I changed, you must know that a UDim2 is shaped like this: the first number is the scale in the X-axis, the second number is the offset in the X-axis, the third number is the scale in the Y-axis and the fourth number is the offset in the Y-axis
		wait()
	end
end)
1 Like

the gui seems to go bigger and smaller now if you try hover it too quickly

1 Like

@Da_RealHonestmam Who do you mean, me or @Batman212369 ?

You have to understand offest math at this point, I found a thread which may help you out:

Kinda done something

function module.AddRoundedButton(Button)
	
  local EasingStyle = Enum.EasingStyle.Quad
  local EasingDirection = Enum.EasingDirection.Out
  local Size = 30
	local AnchorPointX = 0.5
	local AnchorPointY = 0.5
  local Pace = .1
  local Toggle = false
	
       Button.MouseButton1Down:Connect(function()
		
		Button.AnchorPoint = Vector2.new(AnchorPointX, AnchorPointY)
			if Toggle then
				return
				end
			if not Toggle then
			Toggle = true
			Button:TweenSize(UDim2.fromOffset(Button.Size.X.Offset - Size, Button.Size.Y.Offset - Size), 
			 EasingDirection, EasingStyle, Pace )
				end
			end)
		
	  Button.MouseButton1Up:Connect(function()
			Toggle = false
			Button:TweenSize(UDim2.fromOffset(Button.Size.X.Offset + Size, Button.Size.Y.Offset + Size), 
			 EasingDirection, EasingStyle, Pace )
			if not Toggle then
				return
				end
		
			end)
end

Just figured out btw the AnchorPoints.X and AnchorPoint.Y needs to be set to 0.5 for this to work

Don’t touch the offset property of the X coordinate, that’s just a read-only property for you to reference. What you need to do here is add two UDim2 objects which will form a new UDim2 with the applied operations in place. All the numbers are essentially handled column by column.

script.Parent.Size = script.Parent.Size + UDim2.new(0, 20, 0, 0)

By the way, the constructor fromOffset does exist for UDim2 now. If you’re only working with offset, you can use this so that you are only passing numbers for the offset X and Y. Internally it calls the new constructor but passes 0 for scale.

script.Parent.Size = script.Parent.Size + UDim2.fromOffset(20, 0)
5 Likes