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

Removing/Adding Values to Tables?solved

Say I want to add a value to a table.

table = {}
table.insert(table, "remove me")
table.insert(table, "keep me")
table.insert(table, "1")
table.insert(table, "3")

Now I want to remove a certain value from a table.(pretend I don't know the order of the table)

for i, v in pairs(table) do
	if table[i] == "remove me" then
		table.remove(table, i)
	end
end

1 comment

0

INTERESTING

2 answers

✓ Accepted answer

I don't know why but when searching through a table like this where the values aren't set to something else I prefer to sue this method

for i=1, #table do
	if table[i] == "remove me" then
		table.remove(table, i)
	end
end

Also I don't recommend using "table" as the name of your table as it could cause some confusion

Hope this helped!

1 comment

0

table is a syntax and you didn't even call the table

You did table.insert correctly.

mytable = {} -- table is a syntax
table.insert(mytable, "remove me")
table.insert(mytable, "keep me")
table.insert(mytable, "1")
table.insert(mytable, "3")

Now how do we do table.remove?? table.remove() has two arguments. The first one is the table. The next one is the index. In the second script you will see how to use table.remove()

--Insert--
mytable = {} -- table is a syntax 
table.insert(mytable, "remove me")
print(mytable[1])
table.insert(mytable, "keep me")
table.insert(mytable, "1")
table.insert(mytable, "3")
--Remove--
wait(2)
table.remove(mytable,1) -- The first index was a string and it was "remove me" right?? Now it will be deleted from the table myTable
print(myTable[1]) -- Now the first index is now the string "keep me", So the results are now supposed to be "keep me"

Hopefully that is a very detailed answer to your question!! Please submit this answer if it worked!

2 comments

0

well.. I know how to use it I just didn't know how to find a certain value to remove if you didn't know the order. I'll upvote that though

0

Thanks anyway

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