Im having issues with table.remove

Hello developers,

So i posted earlier about an issue i had with removing players in a round. It was fixed, but when there are more than 1 player in the round, and 1 player gets put out of the round, the table for some reason removes everyone. I need help with this. Any help would be appreciated! For anyone that didnt really understand what i meant, Let me rephrase. So if 2 players are in a round, and 1 of them dies. The script attempts to remove them from the table. And it works! But it also removes the other player (that is still in the round) resulting in 0 players in round.

local playerscurrentlyinround = {}

while wait(0.2) do

	for i, plr in pairs(game.Players:GetPlayers()) do
		if plr:FindFirstChild("Contestant") then
				if not table.find(playerscurrentlyinround, plr) then
					table.insert(playerscurrentlyinround, plr)
			end	
		end
	end
	

	for i, plr in pairs(game.Players:GetPlayers()) do
		if plr:FindFirstChild("Contestant") then
			if plr:FindFirstChild("Escaped") then
				table.remove(playerscurrentlyinround, table.find(playerscurrentlyinround,plr))
			end	
		else
			table.remove(playerscurrentlyinround, table.find(playerscurrentlyinround,plr))
		end
	end

	game.ReplicatedStorage.GetPlayersForBar.OnServerEvent:Connect(function()
		script.Parent.PlayerAmount.Value = #playerscurrentlyinround
	end)

	script.Parent.Amount.Text = ""..#playerscurrentlyinround.."/"..script.Parent.PlayerAmount.Value..""

end

you are doing a remove whether the play is Contestant or not in a loop so all will be removed.
Perhaps doing the for loop for only 1 Contestant and 1 Escaped using a bool set what each of them are found and leaving the for loop when both are.

1 Like