Not valid member error?

So I am making this door script, and it works, but if you get the pizza to the wrong house, (The pizza has a value which is the house number) it won’t do anything, but when you get another pizza with the house’s number than you went to on accident, it will not let you put your pizza there. The error it gives me is “PizzaBox” is not a valid member of Backpack. Here is the code.

dog = false

local cf = script.Parent.Part.CFrame


if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and dog == false then

print("found player")

dog = true

local char = workspace:WaitForChild(hit.Parent.Name)

print("found character")

local player = game.Players:GetPlayerFromCharacter(char)

print("player got from char")

local character = player.Character

print("character got from PLAYER")

if char:FindFirstChild("PizzaBox") then

print("Found pizza box")

if char.PizzaBox.HouseValue.Value == 1 or player.Backpack.PizzaBox.HouseValue.Value == 1 then

script.Parent.Part.CanCollide = false

print("turned collide off")

character.HumanoidRootPart.Position = script.Parent.GoThere.Position

character.Humanoid.WalkSpeed = 0

character.Humanoid.JumpPower = 0

1 Like

If a player is holding a tool, that tool will be stored in their character, not their backpack.

This is wrong. If you’re trying to find the PizzaBox, you could define the variable like this:
local PizzaBox = player.Character:FindFirstChild('PizzaBox') or player.Backpack:FindFirstChild('PizzaBox')
and then reference that variable when you need to access the PizzaBox.

It looks like the script checks for it inside the backpack and char

I am trying to make it either or, thats why I put the or, but I didn’t mean for it to check both.

Try this, I haven’t tested it though.

Edit: Also try to use indents in your code to make it easier to read, thanks!

local dog = false
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player and dog == false then
		dog = true
		local char = player.Character
		local pizzabox = char:FindFirstChild("PizzaBox") or player.Backpack:FindFirstChild("PizzaBox")
		if pizzabox then
			if pizzabox.HouseValue.Value == 1 then
				script.Parent.Part.CanCollide = false
				char.HumanoidRootPart.Position = script.Parent.GoThere.Position
				char.Humanoid.WalkSpeed = 0
				char.Humanoid.JumpPower = 0
1 Like

I had an issue before where it would let the pizza go into the other doors, even when the value was wrong, and its happening again, any reason?

If one of them is wrong, it breaks the script

No it does not, I don’t want to sound rude but; FindFirstChild() can return a true or false. Since it’s checking for both using this it will not break the script :grinning: