PlayerName is not a valid member of Players error

im trying to make a wall to where you need to pick up a lantern and a pickaxe, to be able to progress

image
i have looked for at the dev hub and youtube, developer forum

the script is in serverscriptservice and is a normal script

local brick = game.Workspace.wowman

function power (puppy)

	local human = puppy.Parent:FindFirstChild("Humanoid")
	if not human then return end
	local player = game.Players:FindFirstChild(puppy.Parent.Name)
	local hand = puppy.Parent:FindFirstChild("Pickaxe") 
	local back = game.Players[player.Name].Backpack:FindFirstChild("Pickaxe")
		local hand2 = puppy.Parent:FindFirstChild("Lantern")
		local back2 = game.Players[player.Name].Backpack:FindFirstChild("Pickaxe")
	if human and player then 
		if hand or back and hand2 or back2 then
			game.Workspace.mommy.CanCollide = false
		end
		  
	end
end


brick.Touched:Connect(power) 

dont question my function names

Do:

game.Players[Player.Name].Backpack

Edit: I love the names/parameters in your script.

2 Likes

Instead of trying to reference the player with the . method, do it using brackets.

Example:

local back = game.Players[PlayerName].Backpack.FindFirstChildWhichIsA ("Pickaxe")

By just using ., you are looking with the string “PlayerName” itself, and not the value it contains.

1 Like

i tried yours and this is the error that happened image

I believe it should be .FindFirstChild(), not .FindFirstChildWhichIsA. The second option is searching for a ClassName of Pickaxe while the first will find any item that has a name of Pickaxe.

1 Like

Like @NINJAMASTR999 said you need to use :FindFirstChild(), and the error might be because there is a space between :FindFirstChildWhichIsA and (“Pickaxe”) but I don’t know.

1 Like

i tried this and i got the same error. before i changed the script

As the others are saying, you need to change FirstFirstChildWhichIsA to just FindFirstChild. FirstFirstChildWhichIsA looks for an object who’s class is the first parameter. FindFirstChild searches based off of a string value.

Also, the space is not going to generate any errors.

Show me your current script - I can’t find the error if you don’t provide me with the code.

i edited the top script to what it is currently

Also, you might want to look for the tool in their character.
If you want the player to be holding the tool out.

FindFirstChild is a function, not a property. Change it to :FindFirstChild, not .FindFirstChild.

oh yeah your right i didnt see that i didnt change it

1 Like

i personally want it to be both because i need them to have 2 tools, my roblox studio crashed

This is a script I made a while ago:

local ToolChecker = script.Parent

ToolChecker.Touched:Connect(function(other)
	if other.Parent:FindFirstChild("Humanoid") then
	local player = game.Players:GetPlayerFromCharacter(other.Parent)
		if other.Parent:FindFirstChild("insert name of tool here") and other.Parent."name of tool here":IsA("Tool") then
			--run code here
		end
	end
end)

1 Like
local brick = game.Workspace.wowman

function power (puppy)

	local human = puppy.Parent:FindFirstChild ("Humanoid")
	local player = game.Players:FindFirstChild(puppy.Parent.Name)
	local hand = puppy.Parent:FindFirstChildWhichIsA ("Pickaxe") 
		local back = game.Players[PlayerName].Backpack.FindFirstChild("Pickaxe")
		local hand2 = puppy.Parent:FindFirstChildWhichIsA ("Lantern")
		local back2 = game.Players[PlayerName].Backpack.FindFirstChild("Pickaxe")
	if human and player then 
		if hand or back and hand2 or back2 then
			game.Workspace.passpart.CanCollide = false
		end
		  
	end
end


brick.Touched:Connect(power) 

Let’s go through your errors step by step.

  • Line 5 local human = puppy.Parent:FindFirstChild ("Humanoid") → There is a space between FindFirstChild and the parenthesis.
  • Line 7 local hand = puppy.Parent:FindFirstChildWhichIsA ("Pickaxe") → Space between FindFirstChildWhichIsA, and it should be FindFirstChild instead of FindFirstChildWhichIsA.
  • Line 8 local back = game.Players[PlayerName].Backpack.FindFirstChild("Pickaxe") → No such thing as PlayerName, change it to player.Name (since you already have player defined)
  • Line 9 local hand2 = puppy.Parent:FindFirstChildWhichIsA ("Lantern") → See above.
  • Line 10 local back2 = game.Players[PlayerName].Backpack.FindFirstChild("Pickaxe") → There is no such variable/property as PlayerName, if you’re trying to find the player use player.Name (since you already have player)

Hope I helped.

1 Like

thanks SOOOO much you are the homie, but however i got this error after changing the stuff you can see the edits at the top, i got this error: image

It seems like something is trying to find the Name property of something that doesn’t exist. What is on line 11 for you?

I’m guessing that it has something to do with the player.Name thing, are you sure that puppy will have a parent?

im pretty sure puppy should be the players arm or leg and the parent is the character model, and line 11 is:

	local back = game.Players[player.Name].Backpack:FindFirstChild("Pickaxe")

Parts can touch other parts - I’m guessing that the door (when the game first runs) is trying to get the player of another part that it’s touching.

To avoid this, you can just add in

if not human then return end

under the line that defines what human is.

People use :FindFirstChild instead of just saying object.InsideObject because :FindFirstChild will either return the item, or nil. If you use the second option, it will either return the item or give you an error.

What the above line does is that if human does not exist, it will return (basically end) the function instead of continuing. That way, it doesn’t try to get the name of something that doesn’t exist (which will also give you an error). Give it a try?

1 Like