Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why can't the my code find a Gui which is inside the PlayerGui Folder?

I have a code inside a script, inside a ClickDetector, inside a part. When I click the part it should open a Gui which is inside the PlayerGui Folder but I just get the error; InfoGui is not a valid member of PlayerGui

But if I look ínside the PlayerGui Folder it is there! It is spelled correctly, I've checked many times but the script can't find it!

Here's the script;

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

	player.PlayerGui.InfoGui.ImageLabel.Visible = true
end)

7 comments

0

Is this a local or server script? Server side cannot access a player’s PlayerGui.

0

Dude, I already answered on your question

0

But this doesn't work!

0

I'm sorry HaveASip but I've never understood RemoteFunctions or RemoteEvents

0

Did you do what I said? I need to insert remote event into replicatedstorage and put the name of remote event into both my scripts

0

Now I didn't understand what you meant

0

the server cannot see things inside of the PlayerGui unless it was made by the server

1 answer

✓ Accepted answer

The server can't see each clients' PlayerGui's descendants, so you're gonna need a RemoteEvent for this.

We'll need to handle the event on the client using the OnClientEvent event. There we'll enable the player's gui when we fire the event:

-- This will be your client code

local RE = game.ReplicatedStorage:WaitForChild('RemoteEvent') -- assuming you've created a RemoteEvent
local gui = script.Parent -- Assuming this script was parented to the ImageLabel you're making visible

RE.OnClientEvent:Connect(function()
    gui.Visible = true
end)

Then, we'll handle the ClickDetector's mouse event on the server and fire the event to the client who clicked it:

--This will be your server code

local RE = game.ReplicatedStorage:WaitForChild('RemoteEvent')

script.Parent.MouseClick:Connect(function(player)
    RE:FireClient(player) -- Fires the event to the client who clicked the clickdetector
end)

4 comments

0

Should both be normal Scripts?

0

the first one no

0

Should the first one be a LocalScript? And the second one a normal Script?

0

It worked! Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.