--[[
    Returns the ServerPlayerComponents of players that are still in state 'game'
]]

local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")

local PlayerManager = require(ServerStorage.Source.Managers.PlayerManager)

return function(returnComponents)
	local players = {}
	for _, playerComponent in pairs(PlayerManager.getAllPlayers()) do
		if playerComponent.player and playerComponent:getStatus("currentState") == "game" then
			if playerComponent.player:IsDescendantOf(Players) then
				table.insert(players, returnComponents and playerComponent or playerComponent.player)
			end
		end
	end
	return players
end
