local function j()if#PlayerManager.ActivePlayers==0 then RaceManager.OnRaceFinishedEvent:Fire()end end local function H(j,H)if H then PlayerManager.Selections[j]=H end for H,A in pairs(PlayerManager.ActivePlayers)do if A==j then return end end table.insert(PlayerManager.ActivePlayers,j)CheckpointEvent:FireClient(j,{{"\115\101\116\065\099\116\105\118\101";true}})if#PlayerManager.ActivePlayers>=GameSettings.minimumPlayers then onMiminumActivePlayersEvent:Fire()end end local function A(H)CheckpointEvent:FireClient(H,{{"\115\101\116\065\099\116\105\118\101",false}})for A,M in pairs(PlayerManager.ActivePlayers)do if M==H then table.remove(PlayerManager.ActivePlayers,A)j()return end end end

local function checkPlayerCount()	
	if #PlayerManager.ActivePlayers == 0 then
		RaceManager.OnRaceFinishedEvent:Fire()
	end
end

local function addActivePlayer(player, speeder)
	if speeder then
		PlayerManager.Selections[player] = speeder
	end
	
	for playerKey, whichPlayer in pairs(PlayerManager.ActivePlayers) do
		if whichPlayer == player then
			-- Player is already in table
			return
		end
	end
	table.insert(PlayerManager.ActivePlayers, player)
	CheckpointEvent:FireClient(player, {{"setActive", true}})
	
	if #PlayerManager.ActivePlayers >= GameSettings.minimumPlayers then
		onMiminumActivePlayersEvent:Fire()
	end
end

local function removeActivePlayer(player)
	CheckpointEvent:FireClient(player, {{"setActive", false}})
	
	for playerKey, whichPlayer in pairs(PlayerManager.ActivePlayers) do
		if whichPlayer == player then
			table.remove(PlayerManager.ActivePlayers, playerKey)
			checkPlayerCount()
			return
		end
	end
end
