How to make a gui appear when a click detector is clicked?

Hey developers, so recently I’ve had a bug.

I wanted a gui to pop up whenever you clicked a block, but it didn’t work.

Here’s my code.

 local clickdetector = script.Parent

 local Table = script.Parent.Parent

local status = game.ReplicatedStorage.Status

 local gui = game.StarterGui.ScreenGui

 script.Parent.MouseClick:Connect(function()

  gui.Enabled = true

   end)

Help is appreciated.

4 Likes

StarterGui is not part of a PlayerGui. You should do

local gui = game.Players.LocalPlayer.PlayerGui.ScreenGui
3 Likes

I tried that but it didn’t work

1 Like

First of all, you’re changing the value of the Screengui inside of Startergui, which only changes the value inside of startergui. Instead, get the player that clicked the ClickDetector, like this:

script.Parent.MouseClick:Connect(function(player)

From here, go into the PlayerGui and set the ScreenGui enabled to true. Like this:

player.PlayerGui.ScreenGui.Enabled = true

So the code would look like this:

script.Parent.MouseClick:Connect(function(player)
     player.PlayerGui.ScreenGui.Enabled = true
end)
2 Likes

Hmm what’s the output error then?

Also what’s this status for? And btw i assume you are using a LocalScript and not a regular Script. And the LocalScript Placed inside the PlayerScripts or StarterGui and not in workspace cause otherwise its not gonna work

That’s because my game had a number value, and I put it in there in case I need to define it in that script.

1 Like

ClickDetector has a player argument on the MouseClick function.
Example:
ClickDetector.MouseClick:Connect(function(plr)
plr.PlayerGui.GuiToOpen.Enabled = true
end)

Hope this helps.

1 Like

Hm I tried that but it does not work… is there anything you think I’m doing wrong?

1 Like

Was there an error, and did the playergui enable (in the properties)?

I didn’t see any playergui property in the gui

Did you do some debuging? Is there any error in developer Console? Is your script a local script or regular script? If local script if its inside the workspace its not going to work it has to be inside StarterPlayerScripts or StarterGui in your case.

The bug in the console says:

16:59:59 – workspace.Table.ClickDetector.Script:4: attempt to index nil with ‘PlayerGui’

If I’m not mistaken, you want the UI to appear on the player’s screen when they click a block. (please correct me if I’m wrong)

What your code does is simply changing the property of the game’s version of the UI. It’s not actually in the player at that point. You need to index the specific UI in the player’s gui folder for it to enable the UI on the player.

Try putting this in a localscript under the click detector.

local plr = game.Players.LocalPlayer
local gui = plr.PlayerGui:FindFirstChild("ScreenGui")

script.Parent.MouseClick:Connect(function()
   gui.Enabled = true
end)

I’m not sure if this is exactly what your setup will work with, but it’s worth a shot given the small amount of information we have.

1 Like

Does your player have a PlayerGui in it?

If what notsfeelings said doesn’t work either which in theory it should just like what the rest of us said it would be a good thing if you could also provide us an image in the explorer of how things are and located so we can get a better understanding of the issue

I’m not sure how I would do that

Open the “Players” in your explorer window, then open your player, and send a screenshot of whats in it.

Do the following:

Create a remote event, in our case RemoteEvent

script.Parent.MouseClick:Connect(function(player)
 game.ReplicatedStorage.RemoteEvent:FireClient(player)
end)

Client (in a local script parented to the frame)

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
script.Parent.Visible = true
end)

Read for more info here

EDIT: New Server script

Screenshot (44161)

Can you also show us the location of the script and click detector that is being used to open this Gui?