Need help removing players who leave the game from table

I am trying to make a tournament system. When the admin starts the tournament, players get a prompt where they choose if they want to participate.

Players are not removed from the “Players” table when they leave. I can’t find the issue with my code.

My current code (serverside, the issue is not on the client so that code will not be provided):

remChoose.OnServerEvent:Connect(function(plyr)
	table.insert(Players, plyr)
	remStart:FireClient(plr, #Players) -- sends updated player count to admin
end)
local removeplr = game.Players.PlayerRemoving:Connect(function(player) --SHOULD remove players from table when they leave but DOESNT
		for i, v in pairs(Players) do
		print(i) 
		print(v.Name)
		if game.Players:FindFirstChild(v.Name) == nil then
			table.remove(Players, i)
		end
	end
					
	remStart:FireClient(plr, #Players) --send updated player count to admin
end)
2 Likes

why do you have a connected function in a variable, just remove local remove plr = and it should be fine

1 Like

I’ll try that but I do need to disconnect it later.

1 Like

If it is meant to run everytime someone leaves, you dont disconnect

1 Like

This script is on the server, as I stated in the post.

1 Like

well uh either way, that solution didnt work. I am still getting the issue.

that’s not what im looking for though

I only want the players who chose to participate AND are still ingame.

1 Like

Use a table.find() to get the player that left, then call the table.remove with that result.

tried that earlier, had the same issue. ive been losing my mind for 2 hours.

1 Like

You can’t call a function inside a variable, use this instead.


remChoose.OnServerEvent:Connect(function(plyr)
	table.insert(Players, plyr)
	remStart:FireClient(plr, #Players) -- sends updated player count to admin
end)

game.Playes.PlayerRemoving:Connect(function(player)
for i, v in pairs(Players) do
print(i) print(v.Name)
if game.Players:FindFirstChild(v.Name) == nil then
			table.remove(Players, I)

                end
        end
end)

If that doesn’t work then let me try something else. ^

ok so after some negotiation with the guy im making this for, i no longer have to use this.

i have some old code that already works (but removes the UI and player choice) which they are OK with me using.

sorry for wasting everybody’s time.

1 Like