sorry about it but i dont know how made it for _, tool in pairs(backpack:GetChildren()) do for _,tool in pairs(Inventory:GetChildren()) do if tool.Name == "Sword" then tool:Destroy() end
COMMUNITY QUESTION
how to make it so that when you hold an item, it disappears from your inventory?
2 answers
Try this
local player = game.Players.LocalPlayer
for i,v in pairs(player.Backpack:GetChildren()) do
if v.Name == "Sword" then
v:Destroy()
end
end
for i,v in pairs(player.Character:GetChildren()) do
if v.Name == "Sword" then
v:Destroy()
end
end
4 comments
0
i get error
0
This is correct, this shouldn't error. What line does it error on?
0
first line because i uses script in the part i touch him and he dont destroy
0
bruh you can't do local player in server scripts.
make sure the script is a local script or else this will not work.
local player = game.Players.LocalPlayer -- sets a variable for the client (which is invisible to the server that's why it must be local script.
for _,v in pairs(player.Backpack:GetChildren()) do -- Gets every value (things) in the backpack
if v.Name = "Sword" and v:IsA("Tool") then -- checks if the value's name is called Sword and makes sure it is a tool
local sword = v -- sets a variable for the Sword
sword.Equipped:Connect(function() -- does the following if the sword is equipped
sword:Destroy() -- Deletus le sword
end)
end
1 comment
0
hope this works
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Could you elaborate by what you mean by this? Is your Inventory a UI? Did you want to remove tools named Sword removed from the Backpack?
yes
Is this in a local script or a script