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

How do I remove objects from a table?

Asked by 6 years ago

In this script I'm working on; if you click a button it'll insert content from another table into an empty table, and if you click another button it should delete the content from the previously empty table. But an error message would appear saying, "Players.KatsuneSniper.PlayerGui.StartGui.main:207: bad argument #2 to 'remove' (number expected, got Object)"

for i = 1, #currentcam do
    table.remove(currentcam, currentcam[1])
end
0
You have to give it the table number position. TheeDeathCaster 2368 — 6y
0
Thanks KatsuneSniper 31 — 6y
0
Np. TheeDeathCaster 2368 — 6y

1 answer

Log in to vote
0
Answered by
theCJarmy7 1293 Moderation Voter
6 years ago
Edited 6 years ago

table.remove() uses two arguements, an array, and the key you want to remove, not the value. In order to remove the value, try this:

for i = 1, #currentcam do
    currentcam[1] = nil
end

table.remove()

1
STOP STEALING MY ANZERZ! TheeDeathCaster 2368 — 6y
Ad

Answer this question