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.
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.
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.
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)