Why does my tween not tween where I want it to?

Hey! I’m working on a Tween Script for my UI button, where it Tweens whenever the player is hovering over it and/or clicks on the button. I have provided some screenshot of the issue. [EDIT: I didn’t clearly state the issue. I want it to scale in the center of where the actual button is, instead of it scaling to one side only.]

What it looks like normally:

What it looks like when you’re hovering over it:

What it looks like when you click on it:


Here’s the script for it:

local tween = game:GetService("TweenService")
local isHovering = false
local btn = script.Parent

btn.MouseEnter:Connect(function()
	
	isHovering = true
	
	btn:TweenSize(UDim2.new(0.23, 0,0.154, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
end)

btn.MouseLeave:Connect(function()
	
	isHovering = false
	
	btn:TweenSize(UDim2.new(0.221, 0,0.136, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
end)

btn.MouseButton1Down:Connect(function()
	
	btn:TweenSize(UDim2.new(0.165, 0,0.086, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
end)

btn.MouseButton1Up:Connect(function()
	
	if not isHovering then
		btn:TweenSize(UDim2.new(0.221, 0,0.136, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
	else
		btn:TweenSize(UDim2.new(0.23, 0,0.154, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
	end
end)

Have I done something wrong with the EasingDirection or do I need to change/script something?

Because you’ve made it to tween its size smaller?

I see that now, the main issue is (I forgot to clearly state lol) I wanted it to scale but stay in it’s current position in the center - if that makes any sense…

You can keep the button in the centre by changing the property of the button to have the x axis of the anchor point to be 0.5 and then changing the position scale x axis to be 0.5, that way the button stays in the centre of the screen / frame no matter the size.

1 Like

Did that and the scaling is good! My only issue now is that the button moves to the side of the screen when I hover over it and stays there, even if I stop hovering over it and hover back over it. I don’t know if I messed up somewhere in the script or the properties. Here are some screenshots of the issue:

Before:

After:

Make sure you’ve updated the position for all the tweens connected to hovering over the button to have the position x scale axis as 0.5

1 Like

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