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

Why is it saying attempt to index nil with Backpack?

So I have this normal script:

script.Parent.Triggered:Connect(function(player)
	local tool = script.Parent.Parent.Parent.Parent.BoxTool:Clone()
	local path = game.Players:FindFirstChild(player)
	tool.Parent = path.Backpack
	print(player)
end)

This script prints the player correctly. the path variable is fine. But whenever I try to access Backpack, it says attempt to index nil with Backpack. I tried this with FindFirstChild() and WaitForChild(), but it would say attempt to index nil with FindFirstChild() or WaitForChild depending on what I wrote.

1 answer

✓ Accepted answer

FindFirstChild and WaitForChild expect a string, which is the name that it's looking for, but the player is an instance. It might work if you passed in player.Name into FindFirstChild.

However, this is redundant anyways because Roblox already passes in the player who triggered the prompt into the function (that's why you have "player" as an argument in the function instead of just empty parentheses.) Just do:

tool.Parent = player.Backpack

2 comments

0

I'll try this

0

Thanks

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