How to fix ITEM is not a valid member of Backpack

Hi everyone! I’m trying to make a script that gets the value of an IntValue that’s located inside of a tool in the players backpack from a script in ServerScriptService.

The issue is, I always get the error:

Hatchet is not a valid member of Backpack “Players.oopacity.Backpack”

but whenever I check my backpack in the explorer, the tool is there.

local cooldown

local function playerAdded(player)
	local backpack = player:WaitForChild("Backpack")
	
	local hatchet = backpack.Hatchet
	
	cooldown = hatchet:WaitForChild("Configuration").Speed
end

I’m not including the full script because it’s just leaderstats, datastores and stuff but if anyone needs more information to try and solve the problem, I’ll send it right away. I’ve tried using local hatchet = backpack.Hatchet and other scripts to try and debug it but I haven’t been able to fix it. I’ve also checked the forums and other sources for a solution but I haven’t seen anyone with the same error or a solution to it.

Any help is appreciated, thank you!

1 Like

Try this

local cooldown

local function playerAdded(player)
	local backpack = player:WaitForChild("Backpack")
	local hatchet = backpack:FindFirstChild("Hatchet")
	if hatchet then
		cooldown = hatchet:WaitForChild("Configuration").Speed
	end
end
2 Likes

There are 2 things I would assume are the problem.

  1. you are adding the tool on the client
  2. the server hasn’t registered it there yet and you need to use WaitForChild
2 Likes

I just tried that and it doesn’t work. Thanks for helping though

Try using this:

local cooldown

local function playerAdded(player)
	local backpack = player:WaitForChild("Backpack")
	local hatchet = backpack:WaitFortChild("Hatchet")
	cooldown = hatchet:WaitForChild("Configuration").Speed
end

It should work if it waits for it instead of looking for it immediately.

1 Like

I’ve tried using WaitForChild(), and I’m not adding the tool from the client cause the tool is just inside of StarterPack.

Well, I’m not exactly sure of a problem then :sweat_smile: I’m just as confused as you are as to why this doesn’t work.

1 Like

I got

Infinite yield possible on ‘Players.oopacity.Backpack:WaitForChild(“Hatchet”)’

in the console

Then that means it’s not showing up in the player’s backpack?

Check if the tool is Archivable, that could be the problem.

Yes the tool is archivable but I don’t know what that property does

It is showing up in the backpack even when I switch to the servers side when I’m play testing

The problem here was, you want to load an object that is loaded. Try using :FindFirstChild(), like on the given script below.

local cooldown

local function playerAdded(player)
	local backpack = player:WaitForChild("Backpack")
	local hatchet = backpack:FindFirstChild("Hatchet")
	cooldown = hatchet:FindFirstChild("Configuration").Speed
end
2 Likes

I’ve just disabled Archivable and it returns the same error

I got
ServerScriptService.Data.Data:17: attempt to index nil with 'FindFirstChild'

What’s the line that causes that error?

2 Likes

Line 17
`cooldown = hatchet:FindFirstChild(“Configuration”).Speed

It errors for not being able to find the configuration folder but it’s there when I look in the explorer

1 Like

Is the Configuration folder made in an Instance.new() function?
Also is the Instance.new() function located in a LocalScript?

1 Like

It’s not the finding of the Configuration Folder that errored, but instead, “hatchet” is nil.

1 Like

No, it’s just a folder inside of a tool I made and put in StarterPack