ClickDetector needing a double click to open a gui a second time

KJry_s was right.

So I think I fixed it by creating an event and then firing it when the close button is clicked. It gets picked up by the script that opens the gui.

The new script looks like this: If this is wrong please let me know.

Server Script (in the part, with the ClickDetector)

local guiVisible = false
        script.Parent.ClickDetector.MouseClick:Connect(function(player)
        	if guiVisible == false then
        		player.PlayerGui.CollectGui.CraftFrame.Visible = true
        		guiVisible = true
        	end
        end)


        local function closeGui(player) -- Adds an item to the inventory screen
        	player.PlayerGui.CollectGui.CraftFrame.Visible = false
        	guiVisible = false
        end

        game.ReplicatedStorage.Events.closeGui.OnServerEvent:Connect(function(player)
        	closeGui(player)
        end)

Local Script (In the gui frame close button)

local button = script.Parent
        local function onActivated(player)

        game.ReplicatedStorage.Events.closeGui:FireServer(player)

        end

        button.Activated:Connect(onActivated)