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

How do you remove everything from a table?

Asked by 6 years ago
local BCounter = (Gun["C"..BCount])
    table.insert(BTransparentT,BCounter)
    for i,v in pairs(BTransparentT) do
        v.Transparency=1

So I have this function that inserts these variables into a table, but I don't know how to remove them all at once. I tried doing this

for i,v in pairs(BTransparentT)
table.remove(BTransparentT,v)
--But it didn't work, I keep getting an error

Thank you for answering if you did.

2 answers

Log in to vote
1
Answered by 6 years ago

Try testing this out:

local MyTable = {1,2,3,4,5,6}

for i=#MyTable,1,-1 do
    table.remove(MyTable,i)
end

Now try changing it into yours.

0
In order to remove something from a table. Start from collecting them from the end to the start. Not from the start to the end and neither using pairs (May causing errors) magicguy78942 238 — 6y
0
Thank you, it did work but can you explain to me why I cant I start from the start to end? Mr_MilkysButler 47 — 6y
0
@Mr_MilkysButler The reason why that you can't start from the start to the end is that when you do like this {1,2,3} Then It will delete the first variable. And then it turns into this {2,3} After that it will destroy the second variable and turn to this {2} So that's why. magicguy78942 238 — 6y
Ad
Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

This will clear your table of all values:

BTransparentT = {}

BTTransparent will now be an empty table.

0
Thank you, yours worked very well too. Mr_MilkysButler 47 — 6y

Answer this question