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

PlayerGui is not a Valid member of Player?

Asked by
sonuka 24
6 years ago
local function click(player)
    player.PlayerGui.Shop.Frame.Visible = true
end
script.Parent.ClickDetector.MouseClick:connect(click)
0
Print the player: print(player) and see if it is a actual player or not. hellmatic 1523 — 6y
0
Yea it's working sonuka 24 — 6y
0
Oh wait now the error changed to Shop is not a valid member of PlayerGui... sonuka 24 — 6y
0
You will probably have to use RemoteEvents for this as ClickDetectors work by server only and not client. User#20279 0 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

You don't use a click detector like that lol. Put this code in a LocalScript, in a ScreenGui in StarterGui, but not inside the Frame. Remember to put the LocalScript inside of a TextButton.

script.Parent.MouseButton1Click:Connect(function() -- TextButton's have their own mouse click event. 
    script.Parent.Parent.Frame.Visible = not script.Parent.Parent.Frame.Visible
end)

Review: In line 1, we set up the event. Line 2, we change the Visible state of the frame to its opposite, "not true" is false and vice versa. Follow the first steps. Where to put it.

0
It's not a text button it's click detector on a npc sonuka 24 — 6y
0
Why on earth do you have a ClickDetector on an NPC? NPC's shouldn't have ClickDetectors! DeceptiveCaster 3761 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

If you're using FE, this won't work because scripts can't run or change the player's playergui, only localscripts can. Even if FE is off, this is very bad practice because you only need a LocalScript, since the PlayerGui is on the client, not for all the clients. In a nutshell, only use localscripts if you want to make changes on client only, and scripts to do things that show up on all clients. But if you wanted to change it for all clients, well, you would need a remoteevent since as I said earlier, scripts can't access playergui with FE on.

0
And, MouseClick won't work in a LocalScript, just in case you're using one. brokenVectors 525 — 6y
0
Basically, to get this working, add a remote event in replicatedstorage, make the script fire it, then the localscript handles the event and turns the gui on. brokenVectors 525 — 6y

Answer this question