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

Backpack is not a valid member of player?

So I have this script:

local passid = 972737920
local tools = {"BlueFidgetSpinner"}
local GamePassService = Game:GetService('GamePassService')
game.Players.PlayerAdded:connect(function(player)
repeat wait(0.1) until player.Backpack	
repeat wait(0.1) until player.StarterGear
if GamePassService:PlayerHasPass(player, passid) then
for i = 1,#tools do
game.Lighting:FindFirstChild(tools[i]):Clone().Parent = player.Backpack
game.Lighting:FindFirstChild(tools[i]):Clone().Parent = player.StarterGear
end
end
end)

and for some reason, it's telling me: "Backpack is not a valid member of Player". Player does have a backpack though. So does anyone know how i could fix this?

1 comment

1

you could do player:WaitForChild("Backpack") since that makes sure it exists

1 answer

✓ Accepted answer

Here is your problem. It thinks you are trying to do something with the backpack when you do

repeat wait() until player.Backpack

Instead, to use that, do

repeat wait() until player:FindFirstChild('Backpack')

A even better way to wait for a child is to do

player:WaitForChild('Backpack')

Also, you should indent your code.

4 comments

0

The problem now is get no error nor do I get the item.

0

In the output, is there a warning there may be a infinite yield?

0

Nope

0

I'm really sorry, I just realized why I'm getting no error. Thanks so much for helping me, I got it now!

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