What do you want to achieve?
I am trying to open a gui when I click on a part. I have a gui frame and a close button.
What is the issue? Include screenshots / videos if possible!
Everything works and there are no errors, except once I close the gui, after the first time, it takes two clicks on the part to reopen it. Edit: If I keep clicking the part, it opens and closes with each click.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I couldn’t find anything specifically related to this issue on the Hub, however I have rewritten the code a handful of times trying different methods. This is the best I’ve gotten so far. I’m relatively new to scripting so please forgive my naivety.
I have a ClickDetector inside of a part and a script (not local) inside the same part. The script is:
script.Parent.ClickDetector.MouseClick:Connect(function(player)
player.PlayerGui.CollectGui.CollectFrame.Visible = not player.PlayerGui.CollectGui.CollectFrame.Visible
end)
I also have a close button on the CollectFrame with a local script attached to it. it’s script is:
local button = script.Parent
local function onActivated()
button.parent.Visible = false
end
button.Activated:Connect(onActivated)
I’m learning so any and all advice is welcomed, but please explain your response so I can understand, what I did wrong.
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if player == game.Players.LocalPlayer then
player.PlayerGui.CollectGui.CollectFrame.Visible = not player.PlayerGui.CollectGui.CollectFrame.Visible
end
end)
No, just copy and paste the code from the server script into a new client script and put it in the same path (under the same parent) as the old server script.
And add that code with the if statement only to the click detector as you don’t need to check it for the gui.
Note, the if statement should reduce just a little bit of lag;
Quick recap:
Move the code from the server (click detector) script script to a new client script
Give the client script the same parent as the server script
Put the if statements around it to reduce lag (optional)
Wait could you send the code real quick and saying above it if it’s a client script or a server script.
Just so I don’t fall behind on what you’re doing.
Would a remote event help. I understand what you said about the client thinking it’s closed, and the server thinking its open. I’m not sure how to fix that without a remote event then.
Make the Current Server Script into a Local Script
1.1. Make a new Local Script, give the script the same Parent as the Server Script,
1.2. Selecting all the code in the Server Script(by pressing: CTRL + A or Command + A, on mac if I’m right!) Then copy (CTRL + C or Command + C) all the code from the Server Script and Paste it into the Client Script (CTRL + V or Command + V)
Add the if statement to the newly-made Local Script (Optional)
(I don’t wanna seem rude, but I explained it very carefully so you might understand it better. )
Try removing the if statement, I am kinda getting lost myself as it’s easier for me to understand things visually than with words (not sure how I am a scripter, because of that.