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 5 years ago
Edited 5 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

01local Players = game:GetService('Players')
02local Parent = script.Parent
03---------------------------------------------------------
04script.Parent.Touched:connect(function(Hit)
05        local Player = Players:GetPlayerFromCharacter(Hit.Parent)
06    if Player then  
07        game.Players.Player.Name:FindFirstChild('PlayerGui').Token.Item_Recieved.Visible = false
08        script.Parent:Destroy()
09    end
10    end)
0
Small error in your code, you wrote "FindFistChild" instead of "FindFirstChild"* Jomeliter 55 — 5y

2 answers

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

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

maybe should be...

1player: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
5 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:

1local Players = game:GetService("Players")
2local Part = script.Parent
3 
4Part.Touched:Connect(function(Hit)
5    local Player = Players:GetPlayerFromCharacter(Hit.Parent)
6    if Player then
7        print(Player.Name .. " touched " .. Part.Name)
8    end
9end)

Answer this question