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

How do you remove all variables in a Table?

Asked by
xEiffel 280 Moderation Voter
6 years ago

I was using table.insert() to add in players but I want it to clear using table.remove(), but I think table.remove only removes one chosen variable, I want it to remove all. Any help please?

0
local table = {stuff = "1"} table = {} theCJarmy7 1293 — 6y

1 answer

Log in to vote
0
Answered by
dispeller 200 Moderation Voter
6 years ago

Well, there are many ways of doing it, but here are two.

Way 1: The pointlessly excessive way

function clearTable(tab)
    for i,v in pairs(tab) do
        table.remove(tab,i)
    end
end

Way 2: The nice and elegant way

Table = {}

Way 2 just overrides the old table with a new fresh blank one.

0
Thanks xEiffel 280 — 6y
Ad

Answer this question