How to Tween a GUI component that is controlled by a UIGridLayout (Size/Position)

I was recently making my game when I realized that any descendant of a UIGridLayout will not tween size or position. I couldn’t find any post’s that fixed this problem so I figured I should share how I did it.

The best solution that I found was to just make a transparent frame and put whatever UI element you would like to be tweened inside of it.

Example:
Screenshot 2023-11-25 204011

If you would like to use the same tween that I used in the video provided, here is the script that I used (Put this inside of what you would like to tween):

local startsize = UDim2.new(script.Parent.Size.Width.Scale, 0, script.Parent.Size.Height.Scale, 0)

local hoversize = UDim2.new(script.Parent.Size.Width.Scale * 1.02, 0, script.Parent.Size.Height.Scale * 1.05, 0) --change 1.05 to whatever works for you

local clicksize = UDim2.new(script.Parent.Size.Width.Scale / 1.8, 0, script.Parent.Size.Height.Scale / 1.8, 0) --change 1.05 to whatever works for you
print(clicksize)

script.Parent.MouseEnter:Connect(function()
	script.Parent:TweenSize(hoversize,Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.25,true)
end)

script.Parent.MouseLeave:Connect(function()
	script.Parent:TweenSize(startsize,Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.25,true)
end)

script.Parent.MouseButton1Click:Connect(function()
	script.Parent:TweenSize(clicksize,Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.25,true)
	wait(0.05)
	script.Parent:TweenSize(hoversize,Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.25,true)
end)

Hope this helps!

10 Likes

Alternatively you can also use an UIScale, it also scales any UIStroke inside the button as well so it’s pretty useful.

You then won’t need a frame to hold the button, all you’ll need is the UIScale inside the ImageButton/TextButton and you’re set. For scaling you just ween the Scale property of the UIScale object.

:+1:

4 Likes

Didn’t know about that! Thanks!

1 Like