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

PlayerGUI is not a valid member of Player?

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 comment

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");

3 answers

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.

2 comments

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?

1

It should be spelled PlayerGui, I think he's thinking about that.

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.

3 comments

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.

1

Thank you guys so much. Fako, your script worked. Thank you for informing me about the "WaitForChild" function.

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.

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)

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