Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is it saying attempt to index nil with Backpack?

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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
0
I'll try this poop07393cfhi3n2222 4 — 3y
0
Thanks poop07393cfhi3n2222 4 — 3y
Ad

Answer this question