So i have this script inside a tool that contains a numbervalue called "Ammo" the script will destroy the tool once it's value is equals or less than 0. The for i,v script will check if the Ammo's value is equal or less than 0 so that it will remove it from the table.
for i,v Script:
local backpack = plr.Backpack:GetChildren() for i,v in ipairs(backpack) do if v:WaitForChild("Handle").Ammo.Value <= 0 then table.remove(all9mm, v) end if v.Name == "9mm("..v.Handle.Ammo.Value..")" then table.insert(all9mm, v) end end local chosenitem = all9mm[math.random(1, #all9mm)] local function reload() ammo.Value = ammo.Value+1 chosenitem.Handle:FindFirstChild("Ammo").Value = chosenitem.Handle:FindFirstChild("Ammo").Value-1 end repeat reload() until ammo.Value == 15 or chosenitem:FindFirstChild("Handle").Ammo.Value == 0
Destroy tool Script:
local ammo = script.Parent:WaitForChild("Ammo") ammo.Changed:Connect(function(value) if value <= 0 then wait(0.5) script.Parent.Parent:Destroy() end end)
table.remove(table, index) removes the given index, not value; to pull this off you could try: ~~~~~~~~~~~~~~~~~ table.remove(table, table.find(table, value)) ~~~~~~~~~~~~~~~~~