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

Cant access the PlayerGui when firing a event?

I am making a server sided script that clones a tool to the players backpack and I am getting the error "ShopGui is not a valid member of PlayerGui". For some reason, I cant get to the PlayerGui. Here's my script:

Events.Equip.OnServerEvent:Connect(function(player)
    local Character = player.Character
    local Humanoid = Character:WaitForChild("Humanoid")
    local new = game.ReplicatedStorage.Items:FindFirstChild(player.PlayerGui.ShopGui.MainFrame.Selected.Value):Clone()
    new.Parent = player.Backpack
    print("Cloned")
    player.Items:FindFirstChild(player.PlayerGui.ShopGui.MainFrame.Selected.Value).Value = true
    Humanoid:EquipTool(game:GetService("ReplicatedStorage").Items:FindFirstChild(player.PlayerGui.ShopGui.MainFrame.Selected.Value))
    print("Equipped")
end)

Any ideas?

2 answers

This has nothing to do with your Script, it’s primarily your use, following FE regulations. Both the Server and Client (Player) aren’t permitted to access one another as a base component of the intentions in placement of FE. It’s main goal is reducing the probability of exploitation. Please read more about this as it’s inposed of 2017, though can be used for your benefit!

Simply to solve your issue, Instead fire to the Player using :FireClient(client) and work from there. Or plainly work in a LocalScript. Preferably in StarterPlayerScripts

Basically, when a GUI is in StarterGUI, is it not recognized by the server since everything in StarterGUI is cloned locally to the player's GUI and is not part of the server at all. You can solve this issue easily by detecting what the player has selected inside the GUI's LocalScript, and then firing the event with a variable telling the server what they selected, and then use the server to clone the tool to the player.

You could also create a script that clones the GUI manually into the PlayerGUI instead of using StarterGUI, and running this script inside of ServerScriptService, so then the GUI isn't cloned locally, instead it is cloned by the server to the player, so then the server can see the GUI and detect what they have selected.

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