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)

6 comments
Does it give any errors?
09:02:13.503 Handle is not a valid member of Tool "9mm(0)" - Server - Script:59
Why would you check the handle's name with the ammo value as opposed to only the handle's ammo value?
Based on your error message, the script stops because it can't find the handle inside 9mm(0)
sorry i meant there was a numbervalue inside of the tool called "Ammo"
i also tried disabling the destroy tool script so that the for i,v script can detect the tool, but it still didnt remove the tool for some reason