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 6 years ago

Dear Reader,

I am trying to make a script that changes the Parent of my GUI from the PlayerGUI back to the StarterGUI. When I attempt to do so, I got an error.

Please see the following code below.

function PlayerTouched(Part)
        game.Players.LocalPlayer.PlayerGUI.BuyALC.Parent = game.StarterGUI
    end
game.Workspace.ALC.RemovePurchase.Touched:connect(PlayerTouched)

I don't know how to fix this and I need help in doing so.

Thank you.

1
Its not `PlayerGUI:, it's `PlayerGui". The Gui is not supposed to be all capital. Also, it is better to wait for PlayerGui. Like this: :WaitForChild("PlayerGui"); Zafirua 1348 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago

You wrote PlayerGui wrong, also with StarterGui. Remember to just have the words with one caps if there is 2 words connected in a word.

0
What do you mean by I wrote PlayerGUI wrong? I really don't understand where I messed up man. What should I have used instead of PlayerGUI? MichaelAccardi 1 — 6y
1
It should be spelled PlayerGui, I think he's thinking about that. Fako16 13 — 6y
Ad
Log in to vote
0
Answered by
Fako16 13
6 years ago

Try using the WaitForChild thing, here

function PlayerTouched(Part)
        game.Players.LocalPlayer:WaitForChild("PlayerGui").BuyALC.Parent = game.StarterGUI
    end
game.Workspace.ALC.RemovePurchase.Touched:connect(PlayerTouched)

Also make sure this GUI script is a LocalScript cause you're using LocalPlayer.

0
jesus dude, it's not that, he just wrote the playergui wrong, also it would be quite pointless to have a waitforchild, since when the somebody has touched the part, they're already loaded. guidable 42 — 6y
1
Thank you guys so much. Fako, your script worked. Thank you for informing me about the "WaitForChild" function. MichaelAccardi 1 — 6y
0
Pretty sure if you do it this way it will only work in studio but not in game, the Touched event should only be used in server scripts. RoyMer 301 — 6y
Log in to vote
0
Answered by
RoyMer 301 Moderation Voter
6 years ago
Edited 6 years ago

I cannot really understand what you are trying to do, however you should be accessing the player through the :GetPlayerFromCharacter() function to access a player through a server script which must be used since you are using a .Touched event.

Using game.Players.LocalPlayer WILL NOT WORK in a Server Script, yet if you will put it in a Local Script, the script must always be inside of the client and not on the server, hence, if you will put a local script in a part which is in the workspace, this script will only work while you are in Studio but not in game.

This is how to use the :GetPlayerFromCharacter() function

function PlayerTouched(Part)
    if Part.Parent:FindFirstChild("Humanoid") then
        local character = Part.Parent
        local player = game.Players:GetPlayerFromCharacter(character)
    end
end
workspace.ALC.Touched:connect(PlayerTouched)

Answer this question