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

Trying to copy tool into players backpack but getting error?

Asked by
tjtorin 172
7 years ago

I am trying to copy a tool in ReplicatedStorage into the players backpack when they touch the parent of the script which right now is just a normal part but I am getting the error Backpack is not a valid member of MeshPart and I don't know why. Here is the code:

function touch(hit)
    local copy = game.ReplicatedStorage:FindFirstChild("Tool")
    copy:Clone()
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum~=nil then
        copy.Parent = hit.Backpack
        print("Tool Given")
    end
end
script.Parent.Touched:Connect(touch)

1 answer

Log in to vote
0
Answered by 7 years ago

You are trying to copy the tool into the hit itself, instead of player backpack so what you would need to do is

copy.Parent = game.Players:FindFirstChild(hit.Parent.Name).Backpack
Ad

Answer this question