Lightning bugs glow for a variety of reasons through a chemical reaction
Lightning bugs, fireflies, glowworms, or whatever else you may call them based on where you live, are beetles (not bugs) known for their summertime bioluminescent light shows. There is a great deal of diversity among lightning bug species. Most are nocturnal (but not all), most can create bioluminescent light (but not all). In some species both the males & females can glow (but in others only one or the other can glow). They also produce different colors (light green, yellow green, red), depending on the species.
Light show
Lightning bugs have a special organ to produce light, which happens when luciferin (a chemical compound) and luciferase (an enzyme) mix. Both luciferin & luciferase are named after Lucifer, which is the Latin name for the planet Venus meaning “light bringer”, because Venus can appear just before dawn in the night sky. Only later did Lucifer also come to mean Satan.
Why lightning bugs glow varies by species as well as age. In larvae they can glow as a warning to predators telling them “I don’t taste good, don’t eat me.” In adults it’s primarily for mating purposes. Adult males puts on a light show to attract females. Females reciprocate with a glow of their own.
It’s worth noting that the females of the Photuris genus of lightning bugs are known as the “femme fatale lightning bugs” because they imitate the light pattern of other species to attract & then eat the males. Of this genus, the species Photuris pensylvanica is the state insect of Pennsylvania.