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

How to all remove in a table?

Is it possible to remove all in a table without remove the table?

1 answer

✓ Accepted answer

Yes, it’s possible to remove everything in a table without destroying the table itself (is that even possible?). It just takes a simple for loop and table.remove to accomplish this.

Here is an example :

local cleanthistableplz = {"junk", "more junk", 0572859285, 'Wafflez'}

for i = 0, #cleanthistableplz, 1 do
     table.remove(cleanthistableplz, i)
end

So as you can see, I have a table full of strings and stuff. With the for loop, the "i" value goes up based on the number of things in the table and removes them all using table.remove.

Hoped this helped!

I actually don’t know a lot about tables at the moment since I barely use them and wrote this based on this wiki page about tables, so I apologize if something I said was wrong. I also typed all of this on mobile so I can’t even test my script.

3 comments

0

use i=1 instead of i=0, as there is no 0th/0st item in a table

0

Couldn't you just do tableToBeCleand = {} thus removing everything in it?

0

Sorry, I said I don’t know lot about tables right now and I thought I had to use table.remove for that. Didn’t know you can just simply do that.

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