Nowadays, saving energy and cost, along with environmental compatibility is a matter for manufacturers of all kinds of devices and goods. Therefore, in this work, it has been tried to investigate a compound which meets this requirement. Here using density functional theory (DFT) and general gradient approximation (GGA), the two-dimensional HfN as a transition metal nitride and its alloys with Mg and Sc are studied (for two types of structures). Cohesive energy, enthalpy of formation energy, and phonon results confirmed the structural, mechanical, thermodynamic, and dynamic stability of the compounds, a semiconducting bandgap has emerged for the Mg alloy of structure 1. Then, the thermoelectric properties of this alloy as a function of chemical potential and temperature have been studied. The thermoelectric power factor and electronic figure of merit exhibit excellent thermoelectric performance at 400 and 600 K which suggest a good candidate for thermoelectric applications. Finally, the quantum capacitance of the pure structures and their Mg alloys have been studied and compared with the other results.