Help with table.remove() with usernames

Hey all, I am trying to remove a player’s username from the table when they leave the fightzone, however, I’m not sure how to do this.

local InsideFightZone = {}

FightZone.playerEntered:Connect(function(player)
	InZone = true
	table.insert(InsideFightZone, player.Name)
end)

FightZone.playerExited:Connect(function(player)
	InZone = false
	table.remove(InsideFightZone, player.Name) -- Here is where I am struggling
end)

I get the error: invalid argument #2 to ‘remove’ (number expected, got string)

table.remove() takes two arguments:

  • argument 1: the table you wish to remove an element from (table)
  • argument 2: The index of the element you want to remove (number)

You need to supply table.remove() the index of the player in the table, instead of the player’s name.

table.remove(InsideFightZone, table.find(InsideFightZone, player.Name))
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.