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

how to make it so that when you hold an item, it disappears from your inventory?

Asked by 3 years ago

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

0
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? pwx 1581 — 3y
0
yes ltbyks12 16 — 3y
0
Is this in a local script or a script Littlebigplanet40000 77 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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
0
i get error ltbyks12 16 — 3y
0
This is correct, this shouldn't error. What line does it error on? pwx 1581 — 3y
0
first line because i uses script in the part i touch him and he dont destroy ltbyks12 16 — 3y
0
bruh you can't do local player in server scripts. NGC4637 602 — 3y
Ad
Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago

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
0
hope this works NGC4637 602 — 3y

Answer this question