Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

How to make a GUI pop up when brick is clicked?

Asked by 1 year ago

Code I have so far:

script.Parent.ClickDetector.MouseClick:Connect(function(Player)
Player.PlayerGUI.AreYouSureGUI.Frame.Visible = true
end)

I know this question has been asked and answered a lot, but trying those solutions would not work! I get this error:

PlayerGUI is not a valid member of Player

What am I doing wrong here?

0
click detectors only work from remote events now, what you would need to do is have a script in server listening for your click detector to be clicked on, then fire the event client side and have your gui show up from a local script. if you need me to go more in depth just let me know Si_SenorTN 24 — 1y
0
where would i put the remote event? replicated storage? sean_thecoolman 190 — 1y
0
yes Si_SenorTN 24 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

What I did was I used a RemoteEvent, a script in the brick, and a local script in the GUI.

For the script inside the brick I did this:

local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:WaitForChild("ShowGUI") --The RemoteEvent is named "ShowGUI"

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    event:FireClient(player) --Sending a message through the RemoteEvent to change the GUI
end)

Then, with the local script inside the ScreenGui, I did this:

local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:WaitForChild("ShowGUI")

event.OnClientEvent:Connect(function(player)
    game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = not game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible --(I just did this to make it so it would be like a on / off button, you can change the right side of the equals to "true" if you want it to just be a once-activated thing.)
end)

This worked for me, I hope it works for you!

Ad

Answer this question