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

How do I remove a certain element from a table without saying: table.remove(table.5)?

Let's suppose we have the following table with the name of random players:

local SomeRandomPlayers = {"Chris","Milkshake","Something","IDunno","Bob","MeNameJerry"}

What do i do if I want to remove Bob from the table without having to say:

table.remove(SomeRandomPlayers,5)

In the table there will be tons of players added and removed so I will never know wich place Bob is.. Any idea how to do that?

Do I have to do some kind of loop

for i,v in pairs (SomeRandomPlayers) do
if v.Name then
--Still don't know wich place "Bob" is..
end
end

Any help is apreciated!

Thanks!

1 answer

✓ Accepted answer

I'm not sure if there is another way but I think this will work

function RemoveFromTable(list,variable)
	for i,v in pairs(list)do
		if v == variable then
			table.remove(list,i)
		end
	end
end

RemoveFromTable(SomeRandomPlayers,"Bob")

1 comment

0

It worked! Ty mate I'm stupid

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