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

I can't clone items into plr.Backpack?

Asked by 4 years ago

I'm trying to clone a knife gear into a player's backpack using values for an inventory feature. Simple as that. This is testing things like this so that's why it seems so forced to happen:

game.Players.PlayerAdded:Connect(function(plr)
    local KnifeValue = Instance.new("StringValue", plr)
    wait()
    KnifeValue.Value = game.ServerStorage.DefaultKnife.Name
    if KnifeValue.Value == game.ServerStorage.DefaultKnife.Name then
        game.ServerStorage.DefaultKnife:Clone().Parent = plr.Backpack
    end
end)

When I do that it doesn't show up in my backpack nor in the explorer. If I change plr.Backpack to simply plr, it does show up in the explorer. Is there anything extra I have to add?

0
Is code in LocalScript or server script??? User#23252 26 — 4y
0
server SindexMon 6 — 4y
0
try putting it in replicated storage Nickiel13 58 — 4y
0
That didn't work Nickiel SindexMon 6 — 4y
0
Have you tried using waitforchild()? Like game.ServerStorage.DefaultKnife:Clone().Parent = plr:WaitForChild("Backpack") LucarioZombie 291 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
game.Players.PlayerAdded:Connect(function(plr)
    local KnifeValue = Instance.new("StringValue")
    KnifeValue.Parent = plr
    KnifeValue.Value = game.ServerStorage:WaitForChild("DefaultKnife").Name
    game.ServerStorage.DefaultKnife:Clone().Parent = plr.Backpack
end)

This is the correct way to do it, also remember it has to be a server script on serverscriptservice, this will work ONCE every player joins, if you also want to do it every time a player respawns, do this:

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        local KnifeValue = Instance.new("StringValue")
        KnifeValue.Parent = plr
        KnifeValue.Value = game.ServerStorage:WaitForChild("DefaultKnife").Name
        game.ServerStorage.DefaultKnife:Clone().Parent = plr.Backpack
    end)
end)

Hope I helped!

Ad

Answer this question