How to tween a UI frame out when another one is opened

Hello Im kinda new to scripting and have been watching tutorials however i cant seem to find out how to tween a frame out when another one is opened.
Heres the script:

Script

local btn = script.Parent

local isHovering = false
local tweener = script.Parent.Parent.Parent.Pets.Frame

btn.MouseEnter:Connect(function()

isHovering = true

btn:TweenSize(UDim2.new(0.053, 0,0.087, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
script.Parent.HoveSound:Play()

end)

btn.MouseLeave:Connect(function()

isHovering = false

btn:TweenSize(UDim2.new(0.047, 0,0.077, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)

end)

btn.MouseButton1Down:Connect(function()

btn:TweenSize(UDim2.new(0.047, 0,0.077, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
script.Parent.ClickSound:Play()
tweener:TweenPosition(
	UDim2.new(0, 0, 0, 0),
	Enum.EasingDirection.InOut,
	Enum.EasingStyle.Sine,
	1.2,
	true
)

end)

btn.MouseButton1Up:Connect(function()

if not isHovering then
	btn:TweenSize(UDim2.new(0.047, 0,0.077, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
else
	btn:TweenSize(UDim2.new(0.053, 0,0.087, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
end

end)

Thanks!

Use TweenService.

local btn = script.Parent
local isHovering = false
local tweener = script.Parent.Parent.Parent.Pets.Frame

--TweenService
local Tws = game:GetService("TweenService")
local Twi = TweenInfo.new(Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2)

--Sizes
local a = UDim2.new(0.053, 0,0.087, 0)
local b = UDim2.new(0.047, 0,0.077, 0)

btn.MouseEnter:Connect(function()
	isHovering = true
	Tws:Create(btn,Twi,{Size = a}):Play() -- Play the tween
	script.Parent.HoveSound:Play()
end)

btn.MouseLeave:Connect(function()
	isHovering = false
	Tws:Create(btn,Twi,{Size = b}):Play() -- Play the tween
end)

btn.MouseButton1Down:Connect(function()
	script.Parent.ClickSound:Play()
	Tws:Create(tweener,TweenInfo.new(Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,1.2),{Position = UDim2.new(0, 0, 0, 0)}):Play()
end)

No need for the tweens for MouseButton1Down and Up, because it is already scaled.

what i mean is if another ui frame is opened the other one closes
also the tweensize was for when you hover over the ui it gets bigger

I hope this helped although im a little unsure of what you trying to achieve with Button Up.

local btn = script.Parent

local isHovering = false
local tweener = script.Parent.Parent.Parent.Pets.Frame


btn.MouseEnter:Connect(function()
    isHovering = true
    btn:TweenSize(UDim2.new(0.053, 0, 0.087, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
    script.Parent.HoveSound:Play()
end)


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


btn.MouseButton1Down:Connect(function()
    btn:TweenSize(UDim2.new(0.047, 0, 0.077, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
    script.Parent.ClickSound:Play()
    tweener:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 1.2, true)

    --- Since ur Tweening the Frame here then tween the other frame closed?
end)


btn.MouseButton1Up:Connect(function()
    if not isHovering then
        btn:TweenSize(UDim2.new(0.047, 0, 0.077, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
    else
        btn:TweenSize(UDim2.new(0.053, 0, 0.087, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.2, true)
    end
end)

what i mean is if a ui is open the you open another one the first ui closes

Try this but replace otherBtn with your other button that you want invisible whenever you click btn.

local interval = 1

btn.MouseButton1Click:Connect(function()
	if interval == 1 then
		interval = 2
		btn.Visible = true
		otherBtn.Visible = false
	elseif interval == 2 then
		interval = 1
		btn.Visible = false
		otherBtn.Visible = false
	end
end)

local otherInterval = 1

otherBtn.MouseButton1Click:Connect(function()
	if otherInterval == 1 then
		otherInterval = 2
		otherBtn.Visible = true
		btn.Visible = false
	elseif otherInterval == 2 then
		otherInterval = 1
		otherBtn.Visible = false
		btn.Visible = false
	end
end)