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

How do I assign my item's parent to my player's backpack?

Asked by 1 year ago
debounce = true

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild('Humanoid')
    if humanoid ~= nil and debounce then
        local player = game:GetService("Players"):GetPlayerFromCharacter(hit.parent)
        print(player.name)
        hit.Position = Vector3.new(22.176, 1.5, -18.612)
        local sword = game.Workspace.ClassicSword:Clone()
        sword.Parent = game.Players.player.Backpack
        print(sword.parent)
        debounce = false

    end
end)

I'm getting lost in the layers, this doesn't seem to work. I try to make a copy of the sword and then assign its parent to the player's backpack. Why doesn't this work?

0
What are the outputs of your prints? commag 228 — 1y
0
if it is a local script, you can type: sword.Parent = game.Players.LocalPlayer.Backpack kingmaster1033r 0 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

Replace sword.Parent = game.Players.player.Backpack with sword.Parent = player.Backpack

Ad

Answer this question