Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you remove everything from a table?

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

✓ Accepted answer

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.

3 comments

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)

0

Thank you, it did work but can you explain to me why I cant I start from the start to end?

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.

This will clear your table of all values:

BTransparentT = {}

BTTransparent will now be an empty table.

1 comment

0

Thank you, yours worked very well too.

This discussion is preserved as it was. New answers, comments, and votes are closed.