Button Tweening not working for certain buttons?

so, I have a script to make custom button animations, and it works… For, some of them. For some reason, these new TextButtons I have are not tweening, even though some other ImageButtons and TextButtons are tweening just fine. This is my script, located in StarterGui.

for i,button in pairs(script.Parent:GetDescendants()) do
	if button:IsA("GuiButton") then
		local originalSize = button.Size
		button.Activated:Connect(function()
			button.Size = UDim2.new((button.Size.X.Scale * 1.1), (button.Size.X.Offset), (button.Size.Y.Scale * 1.1), (button.Size.Y.Offset))
			button:TweenSize(UDim2.new((originalSize.X.Scale * 1.1), (originalSize.X.Offset), (originalSize.Y.Scale * 1.1), (originalSize.Y.Offset)), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.2, true)
		end)
		button.MouseEnter:Connect(function()
			script.Parent["ui hover"]:Play()
			button:TweenSize(UDim2.new((originalSize.X.Scale * 1.1), (originalSize.X.Offset), (originalSize.Y.Scale * 1.1), (originalSize.Y.Offset)), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.2, true)
		end)
		button.MouseLeave:Connect(function()
			button:TweenSize(UDim2.new((originalSize.X.Scale), (originalSize.X.Offset), (originalSize.Y.Scale), (originalSize.Y.Offset)), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.2, true)
		end)
	end
end

example

1 Like

are these buttons’ ancestor of the screengui? or are they parented in another?

I’m looping through StarterGui, not a ScreenGui, but yes.

I’m testing it, and everything seems to work correctly. Could it have something to do with the [“ui hover”] or the UI not loading in time?

Edit: If you have any GridLayouts or AspectRatios it could be affecting the tweens

1 Like

I tried making it wait until the game loaded, but didn’t work. I do not have any AspectRatios or gridLayouts affecting the buttons.

In that case, it could have something to do with [‘ui hover’], where some buttons may not have that and throws an error.

the thing is, the script is located inside StarterGui, and the [“ui hover”] sound is also inside StarterGui.

It could simply be that the buttons size are not scaled

what do you mean by that exactly?

UIs have a scale and offset for their sizes. If you go into the UI’s properties, you will see it under Size

image

yeah, I know the size property, but what do you mean by scaled?

The Scale/Offset here

sorry if I misunderstood, so basically you’re saying it’s not being scaled correctly?

Correct. Scaling goes from 0 to 1, with 1 being the player’s screen size for any device.

Additionally, if you were to place a frame under another frame, it would size based on that frame’s scale.

wait… When I tried printing the buttons name after confirming it’s a button, it, for some reason. Doesn’t go through. And I also printed when the button was hovered over, and still didn’t print. So the problem is that it doesn’t go through.

It’s probably not loaded in on time

1 Like

Alright, I used a different method to check when the game has loaded and it worked.

1 Like

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