Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Easy?] Not a valid member of players.. token script

Asked by 4 years ago
Edited 4 years ago

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

1 answer

Log in to vote
1
Answered by 4 years ago

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.

0
Well explained, upvoted. User#31525 30 — 4y
0
@rhettsmith6537 , thanks for the advice, it has a error in output saying " Unable to cast value to Object" when i touch the token, pretty sure i set everything up correctly. killerbrasko2002 33 — 4y
0
@rhettsmith6537 it also says the error is on the server sided touch script at line 4 killerbrasko2002 33 — 4y
Ad

Answer this question