Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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)
0
Is this a local or server script? Server side cannot access a player’s PlayerGui. xPolarium 1388 — 5y
0
Dude, I already answered on your question HaveASip 494 — 5y
0
But this doesn't work! Spjureeedd 385 — 5y
0
I'm sorry HaveASip but I've never understood RemoteFunctions or RemoteEvents Spjureeedd 385 — 5y
View all comments (3 more)
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 HaveASip 494 — 5y
0
Now I didn't understand what you meant Spjureeedd 385 — 5y
0
the server cannot see things inside of the PlayerGui unless it was made by the server Donut792 216 — 5y

1 answer

Log in to vote
2
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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)
0
Should both be normal Scripts? Spjureeedd 385 — 5y
0
the first one no User#19524 175 — 5y
0
Should the first one be a LocalScript? And the second one a normal Script? Spjureeedd 385 — 5y
0
It worked! Thank you! Spjureeedd 385 — 5y
Ad

Answer this question