Issue with click detector

So I have a click detector that makes you open up a gui when pressed. Once closed, you cannot open it. Why? (Ask for the script I am happy to send scripts, screenshots and maybe videos)

The code would be helpful for figuring out the problem in this situation.

1 Like

Can you send your code, we can not figure out the problem without it.

Open script:



script.Parent.MouseClick:Connect(function(player)

player.PlayerGui.InfoBox.GoldInfo.Visible = true
end)

close script:
script.Parent.MouseButton1Down:Connect(function()

script.Parent.Parent.Visible = false

end)

Is the open script a LocalScript or a ServerScript?

Open is server and close is local

It is because you close the UI on the Client and Open on the Server.

Open should be a localscipt because it is modifying the client.

Open cannot alter PlayerGui so do it on the client.

Why does it work the first time but then you cant do it after?

Again, you open the UI on the Server and close it on the Client.

So I make both clients, will that work?

1 Like

Now it does not open. So it is this script and it is local
script.Parent.MouseClick:Connect(function(player)

player.PlayerGui.InfoBox.GoldInfo.Visible = true

end)

Because it fires on another Client, use RemoteEvents.

Maybe the problem is that you’re trying to add a ClickDetector into a GUI. All GuiButton’s have a built in clicked function, so if it was a TextButton, just do

TextButton.MouseButton1Click:Connect(function()

end)
local RemoteEvent = [Make a RemoteEvent and make a variable for it]

-- Local script
script.Parent.MouseClick:Connect(function(player)

RemoteEvent:FireClient(player)
end)

-- Normal script
local RemoteEvent = [Make a RemoteEvent and make a variable for it]

RemoteEvent.OnServerEvent:Connect(function(player)
if player.PlayerGui.InfoBox.GoldInfo.Visible == false then
player.PlayerGui.InfoBox.GoldInfo.Visible = true
else
player.PlayerGui.InfoBox.GoldInfo.Visible = false
end
end)```
1 Like

The click detector is in a part.

Also I never understand remote events even I have read them online so i cant do them

This is a great tutorial created by @Alvin_Blox that may help you understand:

just to make it simple just use this code

script.Parent.MouseClick:Connect(function(player)
    player.PlayerGui.InfoBox.GoldInfo.Visible = not player.PlayerGui.InfoBox.GoldInfo.Visible -- not visisble or visible
end)