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

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

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)

1 comment

0

Small error in your code, you wrote "FindFistChild" instead of "FindFirstChild"*

2 answers

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

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)

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