Clicked working only once?

the problem is that it only works once, and then it just doesn’t work again, no errors, I tried print debugging but the whole code works from top to bottom. i am confused?

local cd = script.Parent.ClickDetector
local clicked = false

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
		local gearGui = plr.PlayerGui.GearGui
		if not clicked then
		clicked = true
		gearGui.Frame.Visible = true
		wait(5)
		clicked = false
		print('bad')
	end
end)
1 Like

A significant problem here is that you’re changing client-side UI elements from the server, which can cause all sorts of unwanted effects and easily break scripts. In this case, the issue could be that when the menu is closed from the client the server still sees it as open. You should try using a RemoteEvent and a LocalScript to open the menu from the client.

Edit: For anyone else checking out this thread in the future, I’ve done some testing and I believe I know what the issue with this code was. The server can open the GUI just fine the first time since server changes will replicate to the client. But client changes don’t replicate to the server, so when the client-sided code closes the menu, the server will still see it as open. This is important because if a property is set to what it already was (true to true, in this case) the server won’t bother replicating the change to the client, thus not updating the menu to be visible.

What are you trying to do? All you’re doing right now is setting gearGui.Frame to visible, but if the Gui is already visible then setting it to visible again is not going to affect anything.

ah, ive thought that, and i even tried to use remotes, but then the remotes for no reason at all; were sending some dumb errors

1 Like

It sounds like you may have made some mistake in the code you’re using to control the remotes. If you could post the code and the errors you’re getting that would help with figuring out the issue.

Okay; so it seems it was an issue of misunderstanding. client sided i used wrong directories, but was giving dumb error. so i tried again with focus and now it works lol

It’s pointless to send some remote to the client to open a UI. I’m pretty sure the detecting could be done from the client.
Instead, if something is to be changed in the server, if anything, the client should be the one sending a remote to the server.

That’s true, it does seem that ClickDetectors in workspace will fire on the client.