Removing Player from table

So I’ve read some forums on how to remove players from a table but none of them seem to work in my situation. How would I go about fixing this.

local Player = game.Players.LocalPlayer
local RepStore = game:GetService("ReplicatedStorage")
PlayersToTeleport = {}

local TournyConfig = RepStore:WaitForChild('TournyConfig')
local TournyClosed = TournyConfig:WaitForChild('Closed')

Debounce = false
Cooldown = false
Reload = false
script.Parent.MouseButton1Down:Connect(function()

if TournyClosed.Value == true then return end

if Debounce == false and Cooldown == false then 
	Debounce = true
	
	
	local Char = game.Players:GetPlayerFromCharacter(Player)
	local AlreadyInTable = false
	-- Now make sure the player isn't already in the array
	for _,OtherPlayer in next,PlayersToTeleport do
		if OtherPlayer == Player then
			AlreadyInTable = true
		end
	end
	if not AlreadyInTable then
	-- Add them to the array!
	table.insert(PlayersToTeleport,Player)
	print(Player.Name .. ':Added')
	
	script.Parent.RemoteEvent:FireServer(Debounce)
	
	script.Parent.TextLabel.Text = 'Leave Tournament'
	script.Parent.TextLabel.TextColor3 = Color3.fromRGB(170,0,0)
	
	end
	Cooldown = true
	wait(5)
	Reload = true
	print('Can Leave Tournament')
elseif Debounce == true and Cooldown == true and Reload == true then
	
	
	for _,OtherPlayer in next,PlayersToTeleport do
		if OtherPlayer == Player then
			table.remove(PlayersToTeleport,Player)
			print(Player.Name ..':Left Tourny')
		end
	end
	
	
	

	
end

end)

table.remove removes the given index of a table, and by the looks of it you’re attempting to pass in Player as the index parameter, this is a common mistake and I’ve done this plenty back in the day.

How to fix it? It’s simple, just use the “_” variable in your for loop instead, it should work.

table.remove(PlayersToTeleport, _)

Might want to rename it to i or something though, for readability.

Hope this helps. :slight_smile: