Troubles with enlarging size of UI without changing position

Hello!

I am trying to create a system where when a player hovers over a ui, the ui enlarges. Everything works as intended except when the size increases, the position isn’t centered. Roblox ui increases size to the bottom right. So the position remains the same. But it’s not centered.

In order to fix this I would assume I would have to manually adjust the position during the tween. But I am not sure how I can find the position of the enlarged size.

local Button = script.Parent
local tweenservice= game:GetService("TweenService")

local goal = {}
goal.Size = UDim2.new(0,167,0,99)
--goal.Position = UDim2.new()  Would I add manually like this?

local goal2 = {}

goal2.Size = UDim2.new(0,147,0,79)
--goal2.Position = UDim2.new() 


Button.MouseEnter:Connect(function()

	local tweeninfo = TweenInfo.new(

		0.2,
		Enum.EasingStyle.Quint,
		Enum.EasingDirection.In,
		0,
		false,
		0	
	)
	tweenservice:Create(Button, tweeninfo, goal):Play()
	
	print("Animation Complete")


end)

Button.MouseLeave:Connect(function()


	local tweeninfo = TweenInfo.new(

		0.3,
		Enum.EasingStyle.Exponential,
		Enum.EasingDirection.Out,
		0,
		false,
		0	
	)
	tweenservice:Create(Button, tweeninfo, goal2):Play()


end)

If I do have to find the position. How would I go about doing it?

All help is appreciated!

1 Like

set your UI’s AnchorPoint to 0.5 0.5
It will set the point to middle of the ui

2 Likes

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