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

Does setting a table to nil remove the table?

Asked by 5 years ago

table["Stuff"] = nil expected > print(table["Stuff"]) > "nil" got > print(table["Stuff"]) > "table:..." (why is the format on this messed up?)

Whats wrong with this method? Do module scripts have any affect on this? I assume this is the wrong way of doing this, so can someone enlighten me?``

0
I don't know the position by number. LetterSlayer 42 — 5y

1 answer

Log in to vote
1
Answered by
CPF2 406 Moderation Voter
5 years ago

to accomplish this you have to use table.remove()

http://wiki.roblox.com/index.php?title=Table.remove&redirect=no

Now to answer the question you asked me after, to find the index of a value in a table like you asked, you have to iterate through the table, if you are planning on doing this a lot, I suggest using an index.

local index={}

for i,v in pairs(table) do
    index[v]=i
end

return index["foo"]
0
I tried table.remove().. but the table wasn't at all removed. Confirmed that it was the correct # index. Table was still there... thanks for trying to help my stupidity. LetterSlayer 42 — 5y
0
are you using it correctly? In this instance it would be table.remove(table, 5) if the index of table['Stuff'] was 5 CPF2 406 — 5y
0
If you set the table to nil like this "Data[player.Name] = nil" removes the table. DevingDev 346 — 5y
Ad

Answer this question