Table.remove() isn't working?

So, I’m basically making a queue system where if the Player presses Ready it will fire a Remote event with the Player that’s queuing the Problem is that when the Player presses “Leave Queue” it doesn’t…
(I’ve also add a print for the table after removing the Player and it doesn’t, Yes I checked if the Player is it with table.find()) here is the function which removes the Player from the table


local InQueue = {}




RemoteEvents.LeftQueue.OnServerEvent:Connect(function(Player)
	if Player.StatsFolder.ReadyUp.Value == true and Player.StatsFolder.InGame.Value == false then
		if table.find(InQueue, Player.UserId) then
			warn("Removing Player from Queue..") -- It does print that.
			Player.StatsFolder.ReadyUp.Value = false

			table.remove(InQueue, Player.UserId) -- It doesn't Actually remove the Player
			print(InQueue) -- Prints the Player that also got removed.
			CheckingQueu()
			
		end
	end
end)
1 Like

table.remove() needs the index in the table which it will remove, you put players id. To get the index you can use table.find(), something like this should work:
table.remove(InQueue,table.find(InQueue,Player.UserId))

5 Likes

Hi, that worked But could you tell me more details why that worked?

https://developer.roblox.com/en-u

Removes from array t the element at position pos, returning the value of the removed element. When pos is an integer between 1 and #t, it shifts down the elements t[pos+1], t[pos+2], …, t[#t] and erases element t[#t]. The index pos can also be 0 when #t is 0 or #t+1; in those cases, the function erases the element t[pos].

1 Like

table.remove() wont look thru the table which is specified as first argument, instead it will just remove the value in the index that is specified in the second argument, which means table.remove(mytable,1) will remove the first thing in the table. You have put the player’s id as the second argument so the table.remove() will remove the value at index that has the number you have provided, UserID gives it the number so it will just remove whichever number it is, and its not the player you want to remove. With table.find() you will look thru the table and check if the value you are searching for is in it, if yes then the index of that value in the table will be the result of table.find(), if no then result is nil.

2 Likes

Oh, That makes more sense Thanks!