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

i try to remove a tool from a table but the script still counts said tool as a part of the table?

Asked by 3 years ago
Edited 3 years ago

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)
0
Does it give any errors? RAFA1608 543 — 3y
0
09:02:13.503 Handle is not a valid member of Tool "9mm(0)" - Server - Script:59 GameBuilderLol 58 — 3y
0
Why would you check the handle's name with the ammo value as opposed to only the handle's ammo value? RAFA1608 543 — 3y
0
Based on your error message, the script stops because it can't find the handle inside 9mm(0) RAFA1608 543 — 3y
View all comments (2 more)
0
sorry i meant there was a numbervalue inside of the tool called "Ammo" GameBuilderLol 58 — 3y
0
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 GameBuilderLol 58 — 3y

1 answer

Log in to vote
0
Answered by
0hsa 193
3 years ago

table.remove(table, index) removes the given index, not value; to pull this off you could try: ~~~~~~~~~~~~~~~~~ table.remove(table, table.find(table, value)) ~~~~~~~~~~~~~~~~~

0
i did but for some reason its still not working GameBuilderLol 58 — 3y
Ad

Answer this question