You build up static electricity by walking across the carpet. When you touch metal, it releases the stored energy.positive and negative charges. when you drag your feet against carpet you are negatively charged and so the metal is positively charged so there fore causing an electric shock