How do I make the script know if another frame is open?

I would like the script to understand if another frame is open, so as to close the open one and open the one you want to open, to explain myself better, I want that when you click on “Credits” the “CreditsFrame” frame opens but when you click the button “Donations” closes the “CreditsFrame” and opens the “DonationsFrame”

I tried to read some topics here on the devforum, but I didn’t find anything that helped me, I hope I was clear enough and that someone can at least explain how to do it

If you notice any other error or useless part you can also point it out, I love constructive criticism

Main* (martento57grg Editing) - Roblox Studio (gyazo.com)

local Frame = script.Parent
local TweenService = game:GetService('TweenService')
local ButtonSelected = nil
local FrametoOpen = nil
local Buttons = Frame.Buttons
local ManageDebounce = false

--[[//|Close the frame|//]]--
local function CloseAll()
	wait(2)
	Frame.Visible = false
end




--[[//|General Manager|//]]--
for _, Button in pairs(Frame.Buttons:GetDescendants()) do
	if Button:IsA("TextButton") then
		Button.MouseButton1Down:Connect(function()
			ButtonSelected = Button.Name
			FrametoOpen = Frame.GeneralFrame:FindFirstChild(ButtonSelected.."Frame") 
			print(FrametoOpen)
				if FrametoOpen.Position == UDim2.new(-2,0,0,0) then
					ManageDebounce = true
					task.wait()
					local creditstween =	FrametoOpen:TweenPosition(UDim2.new(0.5, -246,0.5, -176), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 1, false, nil)
					local buttonstween = Buttons:TweenPosition(UDim2.new(0.5, -623,0.397, -134), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 2, false, nil)
					task.wait(1)
					ManageDebounce = false
				else
					ManageDebounce = true
					task.wait(0.5)
					local creditsTween2 = FrametoOpen:TweenPosition(UDim2.new(-2,0,0,0), Enum.EasingDirection.In, Enum.EasingStyle.Quint, 1, false, nil)
					local buttonstween2 = Buttons:TweenPosition(UDim2.new(0.5, -114,0.397, -134), Enum.EasingDirection.In, Enum.EasingStyle.Quint, 1, false, nil)
					task.wait(1)
					ManageDebounce = false
				end
		end)
	end
end


--[[//|Make Start all the functions|//]]

--[[Close all (Play button)]]--
Frame.Buttons.PlayButtonFrame.PlayButton.MouseButton1Click:Connect(CloseAll)

You can add a few lines of code in the event function for “Donations” button to detect if the CreditsFrame is open and then close it.

--[[//|General Manager|//]]--
for _, Button in pairs(Frame.Buttons:GetDescendants()) do
    if Button:IsA("TextButton") then
        Button.MouseButton1Down:Connect(function()
            ButtonSelected = Button.Name
            FrametoOpen = Frame.GeneralFrame:FindFirstChild(ButtonSelected.."Frame")

            if ButtonSelected == "Donations" and Frame.CreditsFrame.Position == UDim2.new(0.5, -246,0.5, -176) then
                -- Close CreditsFrame if it's open
                local creditsTween2 = Frame.CreditsFrame:TweenPosition(UDim2.new(-2,0,0,0), Enum.EasingDirection.In, Enum.EasingStyle.Quint, 1, false, nil)
                local buttonstween2 = Buttons:TweenPosition(UDim2.new(0.5, -114,0.397, -134), Enum.EasingDirection.In, Enum.EasingStyle.Quint, 1, false, nil)
                task.wait(1)
            end

            if FrametoOpen then
                if FrametoOpen.Position == UDim2.new(-2,0,0,0) then
                    ManageDebounce = true
                    task.wait()
                    local creditstween =	FrametoOpen:TweenPosition(UDim2.new(0.5, -246,0.5, -176), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 1, false, nil)
                    local buttonstween = Buttons:TweenPosition(UDim2.new(0.5, -623,0.397, -134), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 2, false, nil)
                    task.wait(1)
                    ManageDebounce = false
                else
                    ManageDebounce = true
                    task.wait(0.5)
                    local creditsTween2 = FrametoOpen:TweenPosition(UDim2.new(-2,0,0,0), Enum.EasingDirection.In, Enum.EasingStyle.Quint, 1, false, nil)
                    local buttonstween2 = Buttons:TweenPosition(UDim2.new(0.5, -114,0.397, -134), Enum.EasingDirection.In, Enum.EasingStyle.Quint, 1, false, nil)
                    task.wait(1)
                    ManageDebounce = false
                end
            end
        end)
    end
end

I mean, i have 3 frames in total, and I don’t want them to open at the same time