GUI objects inside frame not scaling with frame when changed via "tween"

Hello. I’m trying to make a hover effect for buttons that scales the button being hovered using the TweenService assistant SPR but the buttons (a frame with objects inside like a full scaled transparent button that activates the button) don’t scale even though it prints when the scale is changed. I assume that with the scale changing and the scale of the GUI objects not changing proportionally, that I’m doing something wrong. I would be very grateful if someone could help me out.

Here’s my script:

local ogScaleX = btn.Size.X.Scale
local ogScaleY = btn.Size.Y.Scale
local ogPosX = btn.Position.X.Scale
local ogPosY = btn.Position.Y.Scale
local ogParentScaleX = btn.Size.X.Scale
local ogParentScaleY = btn.Size.Y.Scale
local ogParentPosX = btn.Position.X.Scale
local ogParentPosY = btn.Position.Y.Scale
if not btn.Parent:IsA("ScreenGui") then
	ogParentScaleX = btn.Parent.Size.X.Scale
	ogParentScaleY = btn.Parent.Size.Y.Scale
	ogParentPosX = btn.Parent.Position.X.Scale
	ogParentPosY = btn.Parent.Position.Y.Scale
end
btn.Activated:Connect(function()
	btnClick:Play()
end)
btn.MouseEnter:Connect(function()
	--[[
		btn:TweenSizeAndPosition(
			UDim2.new(ogScaleX + btnSizeDiff, 0, ogScaleY + btnSizeDiff, 0),
			UDim2.new(ogPosX - btnSizeDiff/2, 0, ogPosY - btnSizeDiff/2, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			btnSizeTimeIn,
			false,
			nil
		)
	]]
	if btn.Parent.Parent == buttons then
		spr.target(btn.Parent, 0.6, btnSizeTimeIn, {
			Size = UDim2.fromScale(ogParentScaleX + btnSizeDiffMainBtns, ogParentScaleY + btnSizeDiffMainBtns),
			Position = UDim2.fromScale(ogParentPosX - btnSizeDiffMainBtns/2, ogParentPosY - btnSizeDiffMainBtns/2)
		})
	else
		spr.target(btn, 0.6, btnSizeTimeIn, {
			Size = UDim2.fromScale(ogScaleX + btnSizeDiff, ogScaleY + btnSizeDiff),
			Position = UDim2.fromScale(ogPosX - btnSizeDiff/2, ogPosY - btnSizeDiff/2)
		})
	end
	if not btnHover.Playing then
		btnHover:Play()
	end
end)
btn.MouseLeave:Connect(function()
	--[[
		btn:TweenSizeAndPosition(
			UDim2.new(ogScaleX, 0, ogScaleY, 0),
			UDim2.new(ogPosX, 0, ogPosY, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			btnSizeTimeOut,
			false,
			nil
		)
	]]
	if btn.Parent.Parent == buttonsthen
		print(btn.Parent.Size)
		spr.target(btn.Parent, 0.6, btnSizeTimeOut, {
			Size = UDim2.fromScale(ogParentScaleX, ogParentScaleY),
			Position = UDim2.fromScale(ogParentPosX, ogParentPosY)
		})
	else
		spr.target(btn, 0.6, btnSizeTimeOut, {
			Size = UDim2.fromScale(ogScaleX, ogScaleY),
			Position = UDim2.fromScale(ogPosX, ogPosY)
		})
	end
end)

If anyone requests, I can give additional info. Note that I can’t share what most of my GUI looks like because I don’t want to leak a UI remake that I’ve been working kinda hard on. Thanks. I will not be able to answer any replies until morning (4/8/2023 EST), since I’m pretty tired.

I don’t have Studio in front of me, but there are two ways to set the scale of things in the Property Window.

Size is listed as 0,0 with the first 0 being a scalable option and the second 0 being an unscalable size.

Make sure you’re using the first 0 and the second 0 remains a 0.

I’m using UDim2.fromScale which sizes on the scale. Unfortunately, like I said, the size changes and the GUI objects within the buttons (which are frames) do not. However, I didn’t mention one thing. The GUI objects inside the buttons are also scaled, meaning that they should scale whenever the size of the frame is changed. This got me confused, deciding whether to put this post in bugs or scripting support. However, I do believe this is somehow fixable.

I resolved the issue. Since I had a UIGridLayout, the sizes were limited, especially when I tried to set the buttons to scale instead of offset with the UIGridLayout featuring only offset cell sizes. What I did was I grabbed the position of each button and carefully laid them back out without the UIGridLayout. :slight_smile: But you could also achieve this by using a script or the command line if you’re lazy or have too many buttons under a UIGridLayout.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.