I have a model in workspace. I want a Gui to open when clicking on a certain part of the model. Kind of simple, but there is a lot of confusion on devforum.
https://devforum.roblox.com/t/how-to-open-up-a-gui-by-clicking-on-a-brick/260329
I have a model in workspace. I want a Gui to open when clicking on a certain part of the model. Kind of simple, but there is a lot of confusion on devforum.
https://devforum.roblox.com/t/how-to-open-up-a-gui-by-clicking-on-a-brick/260329
I have found a way to do this..
So what you need to do first is, put a part in the workspace and add a: clickdetector, and a normal script ( not local script ) inside of the part.
Then add a remote event inside of replicated storage, call it anything ( i called mine OpenGuiEvent).
Then add a screen gui into starter gui. And put a frame inside of the screen gui and a local script inside of the screen gui too.
For the script inside of the part, the code is:
local replicatedStorage = game:GetService("ReplicatedStorage")
local OpenGuiEvent = replicatedStorage:WaitForChild("OpenGuiEvent")
local part = script.Parent
local clickDetector = script.Parent.ClickDetector
clickDetector.MouseClick:connect(function(Player)
OpenGuiEvent:FireClient(Player)
end)
if you named your remote event to something else, change the variable obviously.
Then for the local script inside of the screen gui, i put in:
local replicatedStorage = game:GetService("ReplicatedStorage")
local OpenGuiEvent = replicatedStorage:WaitForChild("OpenGuiEvent")
local gui = script.Parent
local frame = script.Parent:WaitForChild("Frame")
OpenGuiEvent.OnClientEvent:connect(function()
frame.Visible = true
end)
Before you test it out, make sure you make your frame invisible in the properties tab before you run the game.
To close the gui add in a textbutton inside of the frame. I make the text button a small square shape and I change the text to a capital x to make the close button. I also change text scaled to true and change the background transparency to 1
The code inside of the local script in the frame is:
local frame = script.Parent
local closeButton = script.Parent.closeButton
closeButton.MouseButton1Click:Connect(function()
frame.Visible = false
end)
I hope this works for you.
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
thx
your welcome :) did it work?
yes, but what is the script that closes the script when the button is pressed?
I edited the response. I hope you find this useful.