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

How do I get the position of something in a table?

tablee = {hi = 3, bean = 2, cake = 1}

tablee2 = {"hi", "bean", "cake"}

toomany = {
	hi = 2;
	bean = 4;
	cake = 5;
}

for i,v in pairs(toomany) do
	if v <= tablee[i] then
		print(i.." has too many and I don't know how to get rid of it in tablee2")
		-- table.remove(tablee2, i) doesn't work because i returns "hi" rather than its position in the table
	end
end

The above code needs to get rid of the things in tablee2 when there are too many of them in tablee. This is the method I have to use, because the context I'm using it in forces me to use it like this. I just made this example simpler but similar.

1 answer

i does not return the object in the table. i returns the index.

tablee[i] returns the object in the table.

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