Window Visibility Handler doesn't work

  1. What do you want to achieve? Keep it simple and clear!
    Making a Window Visibility Handler. If you open a GUI but another one is open, it will close and open the new one. If a GUI suddenly gets closed by a notification, it will open back when the notification is closed.

  2. What is the issue? Include screenshots / videos if possible!
    It works, until you close the GUI. You can’t open it again until you open another GUI, and I can’t figure out how I would make the notification toggle

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I don’t really know what else I could try and I searched but couldn’t find anything.

Code:

local playerGui = game.Players.LocalPlayer.PlayerGui

local currentOpenGUI = script.current
local lastOpenedGUI = script.last

for i,v in pairs(playerGui:GetDescendants()) do
	if v:IsA("TextButton") then
		if playerGui:FindFirstChild(v.Name) then
			v.MouseButton1Down:Connect(function()
				playerGui[v.Name].Enabled = true
				lastOpenedGUI.Value = currentOpenGUI.Value
				if lastOpenedGUI.Value then
					lastOpenedGUI.Value.Enabled = false
				end
				currentOpenGUI.Value = playerGui[v.Name]
			end)
		end
	end
end
local players = game:GetService("Players")
local player = players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local function screenGuiToggler()
	for _, screenGui in ipairs(playerGui:GetChildren()) do
		if screenGui:IsA("ScreenGui") then
			screenGui:GetPropertyChangedSignal("Enabled"):Connect(function()
				if screenGui.Enabled then
					for _, otherScreenGui in ipairs(playerGui:GetChildren()) do
						if otherScreenGui:IsA("ScreenGui") then
							if otherScreenGui ~= screenGui then
								otherScreenGui.Enabled = false
							end
						end
					end
				end
			end)
		end
	end
end
screenGuiToggler()

Works perfectly, thanks! Any idea on how I would make a GUI come back after the GUI that closed it closes?