Unable to find any children located in a player's backpack

I am trying to get the player’s backpack’s tools using a server script. My script has no errors, however it still gives me an error when I try to index an existing item in the backpack. What did I do wrong?

Script:

local function onPlayerAdded(player)
	local bakcpack = player:WaitForChild("Backpack")
	print(bakcpack:GetChildren())
	local blaster = bakcpack.Blaster
	blaster:SetAttribute("Ammo", 5)
end

Players.PlayerAdded:Connect(onPlayerAdded)

Video:

Seems like the children of backpack haven’t loaded yet. Try waiting for them just like you did with backpack itself

local blaster = bakcpack:WaitForChild('Blaster')

Also there’s a typo in backpack

1 Like

Items to backpack are added when your character is spawning.

Try this:


local function onCharacterAdded(player)
	task.wait()
	local backpack = player:WaitForChild("Backpack")
	print(backpack :GetChildren())
	local blaster = backpack .Blaster
	blaster:SetAttribute("Ammo", 5)
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end

Players.PlayerAdded:Connect(onPlayerAdded)
1 Like

Tried that, it gave me infinite yield error.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.