Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I open a GUI using a ClickDetector?

Asked by 5 years ago

I have a ClickDetector inside a part. I'm using the following script to open a GUI (placed inside the part itself, not the ClickDetector):

script.Parent.ClickDetector.MouseClick:Connect(function(Player)
    local pgui = Player:WaitForChild("PlayerGui"
    pgui.RefineryGui.Frame.Visible = true
end)

Other info:

  • The GUI is placed inside of StarterGui in studio.
  • I'm trying to have the GUI open only for the player who clicks the part.
  • The GUI contains a button that allows the player to close the GUI. The script I'm using works fine to open the GUI once, but after I close out of it, I can't click the same part to open the GUI again.

Basically, I'm looking for a way to have a player click on a part and have a GUI open (only for the player who clicked the part) that, after it is closed, can be reopened by clicking the part again. Any help is appreciated.

Thank you!

0
I do agree with incapaxx although I have answered the question, you are asking how to do a lot of things to the point where its just us scripting. I have just told you how to open a GUI with a click detector as thats what the title says. Alexander_Ashford 231 — 5y
0
You forgot a bracket on the end of line 2 blocky010101 23 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

To do this you are going to want to fire a remote event. I don't want you to leave here today with a free script so have put a lot of comments and am going to link you some videos:

Lua Book: https://www.lua.org/pil/contents.html AlvinBlox Remote Events: https://www.youtube.com/watch?v=wic-N4JiFss AlvinBlox Remote Functions: https://www.youtube.com/watch?v=-KqiPiE5P74

In terms of how you would do this:

(You would want an Event in Replicated Storage and the GUI in StarterGUI.)

The script you would want in the click detector would be something like this and would be in a server script: ```lua -- This gets the service replicated storage. local ReplicatedStorage = game:GetService("ReplicatedStorage") -- This is a variable which finds the event in Replicated Storage. local Event = ReplicatedStorage.Event -- This is a function that runs when you click the click detector. script.Parent.ClickDetector.MouseClick:Connect(function(Clicked) --This fires the event to the person who clicked it. Event:FireClient(Clicked) end)

``` Then in the GUI you would have a local script like this:

```lua -- Similarly to the first script you need to locate the event. local ReplicatedStorage = game:GetService("ReplicatedStorage") local Event = ReplicatedStorage.Event

--This is the variable for the local player local Player = game.Players.LocalPlayer -- This is a variable which finds the GUI. (Test is the name of the GUI in this case) local Test = script.Parent.Parent.Parent.Parent.Test

--This is a function for what to when the event is fired. Event.OnClientEvent:Connect(function() --This turns the GUI's frame called TestFrame visible. Test.TestFrame.Visible = true

end) ``` Note: The amount of parents needed for the GUI is based on how many parents the script has.

0
Alvin teaches bad practices. Don't even recommend his channel User#24403 69 — 5y
0
Matter of personal opinion, I personally found him very useful as a beginner (which I think he is) so I recommend it. But do understand why you dislike him, and have edited my post to include the Lua Book. Alexander_Ashford 231 — 5y
0
The videos that AlvinBlox have also been helpful for me. In my opinion, he explains things, which not all youtubers do. Sir_funnyguy 4 — 5y
Ad

Answer this question