I'm trying to make a job delivery system where the player picks up boxes and deliver them.. How do I make it so a certain item is removed from their inventory without removing all of the tools. This is what I have so far
local debounce = false script.Parent.Touched:Connect(function(hit) if not debounce then debounce = true local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) if plr then local holders = {plr:FindFirstChild("Backpack"), plr:FindFirstChild("StarterGear"), hit.Parent} game.Workspace.itemStocks.numberofSoap.Value = game.Workspace.itemStocks.numberofSoap.Value + 1 for i,v in pairs(holders) do pcall(function() for i,v in pairs(v:GetChildren()) do if v:IsA("BackpackItem") then v:Destroy() end end end) end end wait(15) debounce = false end end)
Thanks :)
Ok, so what your doing is destroying everything in the inventory that is a tool, but im assuming you want to destroy a specific item so heres what i would do. Im not 100% sure why your going throught every item to destroy one item but if so heres what i would do instead: Instead of seeing if it is a tool, we should check if its name is the name of the tool you want to get rid of.
local debounce = false 02 local NameOfItemWeWantToDestroy = "Box" -- change this to the name whatever you want to destroy 03 script.Parent.Touched:Connect(function(hit) 04 if not debounce then 05 debounce = true 06 local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) 07 if plr then 08 local holders = {plr:FindFirstChild("Backpack"), plr:FindFirstChild("StarterGear"), hit.Parent} 09 game.Workspace.itemStocks.numberofSoap.Value = game.Workspace.itemStocks.numberofSoap.Value + 1 10 for i,v in pairs(holders) do 11 pcall(function() 12 for i,v in pairs(v:GetChildren()) do 13 if v.Name == then -- this will check if its name is the name of the item we want to destry 14 v:Destroy() 15 end 16 end 17 end) 18 end 19 end 20 wait(15) 21 debounce = false 22 end 23 end)
Edit(I understand why your looping through all of those now, so as to delete it from the character backpack and starterpack) Ok :)