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

Attempt to index nil with 'Backpack' ?

i made a script that gives a player a tool, but when i test it it doesn't work and in the output it says:
Attempt to index nil with 'Backpack'
Here's the script:

local trowel = assets.Trowel:Clone()
trowel.Parent = game.Players:GetPlayerFromCharacter(player).Backpack

help

2 comments

0

Are these the only 2 lines in your script? What is 'player'?

1

Your question has insufficient information. Does the player variable come from a PlayerAdded event? Does the player variable come from a For -- In -- Do? The question is too varying for me to give a proper answer.

2 answers

It can be because the script starts running before the Backpack is fully loaded in. Try pasting this script:

local trowel = assets.Trowel:Clone()
trowel.Parent = game.Players:GetPlayerFromCharacter(player):WaitForChild("Backpack",100)

1 comment

0

it doesn't work and in the output it says Attempt to index nil with 'Backpack'

Easy, Now look why are you trying to find player from character when you already have it. Another is it has to be game.Players.LocalPlayer:GetCharacterFromPlayer()

Just use this.

local trowel = assets.Trowel:Clone()
trowel.Parent = game.Workspace.LocalPlayer.Backpack

Also, make sure it's a LocalScript and it's parent is StarterPlayer > StarterPlayerScripts

Also, if that's all you need then just put the tool in StarterPack.

2 comments

0

It's a very bad idea to clone tools on a client, it won't be visible to others.

0

Yes, Ik i said its better to put it in starterpack. Then you would need to use bunch of events.

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