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

Is there a way to remove objects from a table?

Okay so say I put all the game players into a table. And then I mathmatically choose a single player from that table. If I want to remove that player from the table how would I do it? It seems you can't just table.remove an object.

4 comments

0

Please be more concrete. What are you trying to do? What is the number that you're trying to assign? And why?

0

Okay so you can't remove an object from a table. Is there a way to do that?

0

That is basically what I am trying to ask.

0

For key, value tables simply set the value to nil e.g. [table key] = nil

1 answer

✓ Accepted answer

table.remove removes something at a particular index. You have to know where the object is in the table to be able to remove it.

local players = game.Players:GetPlayers()

local player = -- some player, decided somehow
for i = 1, #players do
	if players[i] == player then
		table.remove(players, i)
	end
end

1 comment

0

Okay thanks!

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