Why can I only use ClickDetector once?

ClickDetector only works once for some reason. Anyone know why?

Open Gui Script:

local prompt = script.Parent


prompt.MouseClick:Connect(function(Player)
	Player.PlayerGui.Blogs.one.Enabled = true
end)
end)

Close Gui Script:

local button = script.Parent
local localplayer = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()
	localplayer.PlayerGui.Blogs.one.Enabled = false
end)

If anyone knows how to fix this, please let me know, Thank you!

2 Likes

Because you a few always opening it, your scritp should look lite:

local prompt = path
local button = path
local LocalPlayer = game: GetService(“Players”).LocalPlayer

local open = false


prompt.MouseClick:Connect(function(Player)
if open == false then
	Player.PlayerGui.Blogs.one.Enabled = true
open = true
end)
end)

button.MouseButton1Click:Connect(function()
if open == true then
	localplayer.PlayerGui.Blogs.one.Enabled = false
end)
2 Likes

Change this to:

button.MouseButton1Click:Connect(function()
	localplayer.PlayerGui.Blogs.one.Enabled = not localplayer.PlayerGui.Blogs.one.Enabled
end)
prompt.MouseClick:Connect(function(Player)
	Player.PlayerGui.Blogs.one.Enabled = not Player.PlayerGui.Blogs.one.Enabled
end)
end)
1 Like

Try doing this in your ClickDetector script:

local click = script.Parent

click.MouseClick:Connect(function(Player)

Player.PlayerGui.Blogs.one.Visible = true

end)

Also, do this in a LocalScript parented to the exit button of your GUI.

local button = script.Parent

local player = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()

player.PlayerGui.Blogs.one.Visible = false

end)

2 Likes

From where and why you got 2 end) ?

Change this to -

local prompt = script.Parent


prompt.MouseClick:Connect(function(Player)
	Player.PlayerGui.Blogs.one.Enabled = true
end)

Do you have more lines of code and this code is under that code ?

3 Likes

This is obviously a server script. When the server enables the UI, you see it because it’s replicated (Server → Client), but when you disable the UI via a LocalScript, it doesn’t replicate and the server still thinks the UI is opened (Client → Server X).
Use RemoteEvents.

3 Likes

It’s far from wise to network guis in the first place.

1 Like

Also, you need to decide whether you want to go client-sided or server-sided. You can’t just go both sided together. Now without the use of RemoteEvents, I have three-different methods.

1st Method

local prompt = script.Parent

prompt.MouseClick:Connect(function(Player)
	Player.PlayerGui.Blogs.one.Enabled = true
    local button = player.PlayerGui.ScreenGui.Whateverbutton
     button.MouseButton1Down:Connect(function()
     Player.PlayerGui.Blogs.one.Enabled = false
end)
end)

2nd Method

local prompt = script.Parent

local plr

prompt.MouseClick:Connect(function(Player)
	Player.PlayerGui.Blogs.one.Enabled = true
    plr = Player
end)

 local button = plr.PlayerGui.ScreenGui.Whateverbutton
     button.MouseButton1Down:Connect(function()
     Plr.PlayerGui.Blogs.one.Enabled = false
end)

3rd Method
-Be purely client sided.

Isn’t the most simple solution to just keep the prompt local? This activates a GUI, so it makes sense to keep it local.

Just combine both of your scripts as a LocalScript, and that should do it.

You don’t need Remotes here. Is the server going to replicate what you do? No, exactly.

You don’t really need to have this on the server, as everyone has already said, its just GUI. I’d understand if it was something more important but

  • ping will be a factor for GUI events since its now run on the server
  • far more confusing and requires more locals and paths
  • is generally slower and less efficient

i’d just do this all locally instead, its far better and more efficient.