Issue with showing a gui

So basically i have a part in the workspace, and i have a gui into the Player gui.
When you click the part the gui had to set to visible but it doesn’t work. I tried two ways of making it visible.
The first one:

function Click(Player)
local gui = Player.PlayerGui:FindFirstChild("menu")
if gui then
gui.Outline.Visible = true
end
end
script.Parent.ClickDetector.MouseClick:connect(Click)

Which does not work but at the same time there is not any errors in the output, 
and the second one:

function Click(Player)
print("works")
Player.PlayerGui.menu.Outline.Visible = true
print("works")
end
script.Parent.ClickDetector.MouseClick:connect(Click)

Which shows an error in the output which says: menu is not a Valid member of the PlayerGui
I know my way of doing that is kinda outdated but i want to use this way in the script.
Anyone has any idea of what’s happening?

Are you using a normal script? If so, then you can’t do that.

Clients’ guis are cloned on their client, so it won’t replicate to the server. Therefore, the server can’t see the clients’ guis.

This should be done in a local script

Try using
Player.PlayerGui:WaitForChild(“menu”) and see if that works. If it doesn’t make sure you are using a localScript.

1 Like

The Server can only access objects in the PlayerGui that it put there. If you have your gui in StarterGui then you’ll have to use a LocalScript to access it since a regular Script won’t be able to access it

1 Like

It can, it just can only see things put there by a server script.

@HardNinjaGreatorDev, how is the GUI (called menu) getting into the PlayerGui in the first place? Is it inserted by a local script or the StarterGui? If you want it to be seen by the server, you have to clone the GUI into the player’s PlayerGui with a server script. If not, yes you must use a local script.

Yes, I just assumed that he had the GUI in StarterGui. I’ll edit my post to reflect that

Change this to a local script and use this code.

local Player = game.Players.LocalPlayer

Local scripts are individual for each client meaning every client has one and the local player is getting that individual client (maybe someone else can explain this a bit better)

local Player = game.Players.LocalPlayer
local ClickDetector = workspace:WaitForChild('Part'):WaitForChild('ClickDetector')

We’re waiting for the instance Part and ClickDetector to show up in the workspace and referencing it in a variable called ClickDetector

local Player = game.Players.LocalPlayer
local ClickDetector = workspace:WaitForChild('Part'):WaitForChild('ClickDetector')

local PlayerGui = Player:WaitForChild('PlayerGui')

ClickDetector.MouseClick:Connect(function() --
    PlayerGui.menu.Outline.Visible = true
    print('Works')
end)

With this we are waiting for the players PlayerGui to load and assigning it to the variable PlayerGui
With the MouseClick function we won’t need the parameter of playing like in the server as we already know who the player is

Now we are referencing the menu using the PlayerGui variable we assigned and making outline visible set to true.

If we wanted to close this we can use Outline.Visible = not Outline.Visible
This changes true to false and vice versa.

Hope this helps, let me know if anything doesn’t work as I haven’t tested it in studio just yet.

Please put your code in a code block so we can all see it more clearly. Also be sure to indent your code because that’ll help in readability for both us and yourself.

```lua
-- Your code
```

becomes

-- Your code

You should also provide all the information necessary for us to assist you with your problem. For example, we don’t know your object hierarchy, all we see is your code. You could be using the wrong script type or not have your entities set up properly.