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

Tool does not get cloned to players backpack and outputs error?

Asked by
iladoga 129
5 years ago

Hi I have a script that basically just clones a tool and puts it in the players backpack. But I keep getting the error:

"Backpack is not a valid member of player"

I am almost certain I am referencing the right thing and this is very very confusing cause I have done very similar stuff before and it has worked.

Here is my code. SERVER SCRIPT

game:GetService("Players").PlayerAdded:connect(function(player) 
    if player.Name == "iladoga" or player.Name == "FrostyMan88" then
        local cloene = game:GetService("ServerStorage")["Founders Machete"]:Clone()
        cloene.Parent = player.Backpack
    end
end)

Again it just outputs that error. Thank you for taking your time looking at this.

1
Try doing player:WaitForChild('Backpack'). Sometimes the Backpack doesn’t load in fast enough which makes your script error. User#20279 0 — 5y
0
what he said and in general you wanna wait for player and his descendants, such as character humanoid backpack etc... Nogalo 148 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago
game:GetService("Players").PlayerAdded:connect(function(player) 
    if player.Name == "iladoga" or player.Name == "FrostyMan88" then
    player:WaitForChild("Backpack")
        local cloene = game:GetService("ServerStorage")["Founders Machete"]:Clone()
        cloene.Parent = player.Backpack
    end
end)
2
I hate to be that guy but `:connect()` is deprecated. Also it might be better to tell the person what's wrong instead of giving them a script to copy and paste. Optikk 499 — 5y
Ad

Answer this question