-- Puts players into an active players table and runs readyPlayer for each player in that table

function PlayerManager.preparePlayers()
	-- Get all spawn locations in the folder
	local map = mapManager.getMap()
	if not map then return end
	
	local spawnLocations = mapManager.getSpawnLocations()
	if not spawnLocations then return end
	
	local availableSpawnPoints = spawnLocations:GetChildren()
	
	-- Get active players
	local players = Players:GetChildren()
	
	-- For every active player, load them into a table, and ready them with everything needed for gameplay (tools, listeners, spawn)
	for playerKey, whichPlayer in pairs(players) do
		table.insert(activePlayers,whichPlayer)

		-- Gets a spawn location and then removes it from the table so the next player gets the next spawn
		local spawnLocation = availableSpawnPoints[1]
		table.remove(availableSpawnPoints, 1)
		readyPlayer(whichPlayer, spawnLocation)
		
		-- Set player walkspeed
		local character = whichPlayer.Character
		local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			humanoid.WalkSpeed = gameSettings.roundWalkSpeed
		end
	end

	-- Bind destroy action
	actionManager:BindGameActions(players)
	
	-- Update the value so the starting players can be displayed on the GUI
	playersLeft.Value = #activePlayers

end
