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

[Easy?] Invalid member of Players... any help?

Asked by 4 years ago
Edited 4 years ago

The code is below, the issue is, it says player is not a valid member of players, but when i do print(player) it prints the correct name. EDIT

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)

0
Small error in your code, you wrote "FindFistChild" instead of "FindFirstChild"* Jomeliter 55 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

you used "plr" in your statement on line 5 but i think you were supposed to use "player"

maybe should be...

player:FindFirstChild('PlayerGui').Token.Item_Recieved.Visible = false

right?

patty cake patty cake patty cake

Ad
Log in to vote
0
Answered by
Syclya 224 Moderation Voter
4 years ago

You are using FindFirstChild wrong. It is mainly used to check if something exists or not by using an if statement. FindFirstChild takes about 20% longer than using dot operator, and almost 8 times longer than simply storing a reference to an object.

The server shouldn't handle UI-related things. You should look into RemoteEvent:FireClient().

Here's an example of how you get the player that touched a certain part:

local Players = game:GetService("Players")
local Part = script.Parent

Part.Touched:Connect(function(Hit)
    local Player = Players:GetPlayerFromCharacter(Hit.Parent)
    if Player then
        print(Player.Name .. " touched " .. Part.Name)
    end
end)

Answer this question