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

How do I insert an item into the players backpack?

Asked by 5 years ago

Alright, so I need to insert a tool into a players backpack when a tool they are holding touches a part. How do I do so?

Heres the script I tried to make:

local tool = script.Parent

local Handle = tool.Handle

Handle.Touched:connect(function(hit)

end)

if debounce == true then

return

end

debounce = true

if Handle.Touched:connect(function(hit) Name = "123456" then clone.game.ServerStorage.cookedbred = plr.Backpack

end

PLEASE HELP!!! NEED THIS SOON!!!

0
I edited the answer, its been tested in studio this time cmgtotalyawesome 1418 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Edit: I have no idea what I was thinking before because that code had a lot of errors to fix. The correct script is located below:

local tool = script.Parent
local Handle = tool.Handle
local debounce = false

Handle.Touched:connect(function(hit)
    if debounce == true then
        return
    end
    debounce = true
    if hit.Name == "123456" then
        local clone = game.ServerStorage.cookedbred:Clone()
        clone.Parent = game.Players[Handle.Parent.Parent.Name].Backpack
    end
    wait(1)
    debounce = false
end)

Sorry about the last answer. Please accept this one if it helped and don't hesitate to ask questions.

0
ok DannyDxmpster 2 — 5y
0
22:44:57.984 - Players.DannyDxmpster.Backpack.uncooked-bred.Script:17: attempt to index global 'hit' (a nil value) unfortunately that error happened, idk what it is DannyDxmpster 2 — 5y
Ad

Answer this question