How can i get the GUI to always go to the center of the screen?

local button = script.Parent.Parent.userInterface.badgeToggle
local badgeFrame = script.Parent.Parent.userInterface.badgeFrame

local isDown = false

badgeFrame.AnchorPoint = Vector2.new(0.5,0.5)
badgeFrame.Position = UDim2.new(0.372, 0,-1.101, 0)

local function toggleClicked()
	if isDown == false then
		badgeFrame:TweenPosition(UDim2.new(.372,256,.101,356), Enum.EasingDirection.Out,  Enum.EasingStyle.Quint, 1)
		isDown=true
	else
		badgeFrame:TweenPosition(UDim2.new(0.372, 0,-1.101, 0),Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 1)
		isDown=false
	end
end

button.MouseButton1Click:Connect(toggleClicked)

What do you mean “go to the center of the screen”. This just looks like a regular ui toggle.

Hello! To move the GUI to the center, you must set AnchorPoint to (0.5, 0.5), which you have already done.
Then when you want to move it to the middle, change the position to UDim2.new(0.5, 0, 0.5, 0) - it should always keep it in the middle, even after u change the size.

6 Likes