Invalid member of players.... the code is below, its a token and once you step on it it's supposed to open a local GUI for you and then destroy the token but it's not working. (The destroy alone IS working but with the GUI it's not)
local Players = game:GetService('Players') local Parent = script.Parent --------------------------------------------------------- script.Parent.Touched:connect(function(Hit) local Player = Players:GetPlayerFromCharacter(Hit.Parent) if Player then game.Players.Player.Name:FindFirstChild('PlayerGui').Token.Item_Recieved.Visible = false script.Parent:Destroy() end end)
Note: This is NOT a local script, and the game is R6
You have multiple issues here. One is that you can't go into the PlayerGui with a server script. Everything within the PlayerGui is client sided, so it's not possible to access it through the server without using RemoteFunctions or RemoteEvents. If you're trying to close a GUI for the player when a token is touched, I would make a RemoteFunction in Replicated Storage, and then make a local script within the StarterGui. In that local script include this code
--Local
local Player = game.Players.LocalPlayer local CloseRemote = game.ReplicatedStorage.Close CloseRemote.OnClientInvoke = function(plr) if plr == Player.Name then local ScreenGui = script.Parent --Find the gui you need from there end end
The server script inside of the token will need to be like this
--Server
script.Parent.Touched:Connect(function(touched) local PlayerFound = game.Players:GetPlayerFromCharacter(touched.Parent) if PlayerFound then game.ReplicatedStorage.Close:InvokeClient(PlayerFound.Name) end end)
Your second issue is that you can't assign a variable a value and then use it to get something further in the workspace. In your case, you assigned the Player variable a value of the player found in game.Players. If you tried to do game.Players.Player, the value would equal to nothing. In the workspace, you have to use :FindFirstChild to get things you need
Hope this helped.