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

Trying to make this clearer. I apologize for the confusion, but I appreciate the patience.

This is the part in the workspace
Capture 1

This is the gui in StarterGui
Capture 2

This is gui on screen

The server script works but the local script does not open the gui.

No worries, if I’m right we’re both confusing each other.
Could you test a few things for me:

  • Put a lot of print()'s inside every function/if statement (do this in the script which doesn’t work) then test it and see what the client runs when you click the part;
    With a lot of print()'s I mean just putting for every line you go up you put a print() after that.

And could you tell me if the client runs when you click and/or if the if-statement inside the function runs

We’ve become scientists!

  • So when the server script is in the part it runs on the server (prints in output)and the click detector works.
    the gui close(client) script runs on the client.

  • When the client script is in the part there is no output, and the gui does not print anything in the output

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)

I don’t know if an else function would have helped as it was pointed out that the server and the client were not communicating. I ended up using a remote function to make it work.