GUI Opening once but not again

Hey there,
I got this script here that opens a gui for the player when they click a part. It works once but after you close it, it doesn’t open again (the close script is in the button.)
Script

local part = script.Parent
local detector = script.Parent.ClickDetector
local OpenAsk = game.ReplicatedStorage.OpenAsk


detector.MouseClick:Connect(function(player)
	local frame2 = player.PlayerGui.BoothGui.Frame2
	frame2.Visible = true
	end)
1 Like

perhap using a localscript, not a server script :sweat_smile:

1 Like

Do you know any work around that could work?

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Part = script.Parent
local ClickDetector = part.ClickDetector
local OpenAsk = ReplicatedStorage.OpenAsk

ClickDetector.MouseClick:Connect(function(Player)
    local Frame2 = Player.PlayerGui.BoothGui.Frame2

    Frame2.Visible = not Frame2.Visible
end)

try this, since Visible is a boolean we can do Boolean = not Boolean, this makes the boolean it’s opposite

1 Like

Hey there thanks so much for your help, It now works more than one time. However after the first time you click it it takes 2 clicks for the gui to be visible again, If you have a fix for this that would be amazing, If not dont worry about it and thank you so much

could you send a video on this so I can get a better idea on the problem?

1 Like

yep gimme 1 second
303030303030

Here you go, Basically when I have to click the board twice for it to work

when you click on close are you changing the Visible property?

1 Like

Yes the line of code is

frame.Visible = not frame.Visible

well now i’m confused, don’t know what could be causing this

1 Like

what is this going to do?
Visible will always be true!!!

Click detector works both server-side and local side. Mind explaining the open ask variable. Also, I recommend you use local side because it relies on the player and reduces unneeded latency rather than using remote events or remote functions. As well as reducing strain on the server which affects other players. Its strain on the server may be minuscule but it adds up. Remember if the server scripts cause too much strain it affects all players rather than players with poor PC specifications. Now for the main reason why it takes twice I assume the close script is a local script making visible = false. However, server-side it is still seen as visible due to filtering enabled. You can view this by switching to server-side when testing by hitting the “Current: Client” and switching back to the client-side is vice-versa. The server and client both see the GUI as visible = false at the beginning which is why it takes one click. However, after the first click due to the server-side which replicates to the client makes it visible. it makes it only one click because “not booleanVariable” just flips the boolean. When closing it for the first time it is now visible=false client-side, but remains visible=true on sider side. Since the server opens it but doesn’t close it, the server still views it as visible it will take two clicks due to the “not” statement. One-click to make it visible=false server side even though it is already visible=false on the client-side. Since it sets it to false server-side and replicates to the client since the client already views it as false it is noticeable. However, the second click turns it from false to true.

Now for the solutions

Best solution - make it all client-side(local script in GUI) for both closing and opening
Pros - Less Strain on the server, less latency
Cons - More vulnerable to exploiting however in this case it isn’t because the GUI is already in the
player/ client visible side of the game, which allows an exploiter to make it visible whether it
server-sided or client-side scripts. Only bad to use when you’re attempting to hide guis for
such as easter eggs or executing actions like banning a player that depends on if statements
to make sure a player is an admin. These if statements can be easily lied about on client
side, but server-sided scripts are out of exploiter control, all they can do is fire the remote
event or remoteFunction, but the server-sided if statements will catch that false firing and
prevent the exploiter from succeeding.

Solution #2 - Make everything server-sided, whether by remoteEvents/remoteFunctions or game event functions
Pros - Prevent exploiting, however not applicable in this case since the GUI is already in the player
and a server script won’t stop the exploiter from making it visible
Cons - More strain on the server, more latency

Solution #3 - Be more specific with booleans. Rather than using not, use true or false.
Pros - Fix the problem, let closing be zero latency.
Cons - Opening will continue to be server sided so it is still having latency, as well as server strain

Here is a local-sided script of the best option, you can put this local script in the frame or GUI, just change the variables as the instruction says to.

local Frame = script.Parent--Set to main frame

local Close = Frame:WaitForChild("CloseButton")--Set to close button location of name within frame.

local ClickPart = game:GetService("Workspace"):WaitForChild("ClickPartName")--Set to click part location and name. If inside another model use :WaitForChild() and repeat till you get to click part.
local OpenDetector = ClickPart:WaitForChild("ClickDetector")--Set to click detector name

OpenDetector.MouseClick:Connect(function()--Setting frame visible/opening the gui
	Frame.Visible = true--Opens it
end)

workspace.TextButton.MouseButton1Down:Connect(function()--Closing gui/making it invisble. Change to MouseButton1Click or MouseClick depending if you want gui to close upon click down, or upon the lift after a click has been fully released.
	Frame.Visible = false--Closes it
end)
2 Likes

Not sure why you didn’t get this solution earlier, but here:

local part = game.Workspace:WaitForChild("Part")
local clickDetector = part:WaitForChild("ClickDetector")
local toggle = false

clickDetector.MouseClick:Connect(function(player)
	local frame2 = player:WaitForChild("PlayerGui"):WaitForChild("BoothGui"):WaitForChild("Frame2")
	if toggle then
		frame2.Visible = false
		toggle = false
	elseif not toggle then
		frame2.Visible = true
		toggle = true
	end
end)

Works as a local script.

1 Like