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:
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!
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.