It is the amount of melanin in their bodies that affects their skin complection. people with darker skins would have a great amount of eumelanin (a type of melanin) in their skins.
another explanation would be that
In Charles Darwin's theory, there are lots of factors that can effect a person's genes, thus mutation occurs, or simply saying, HUMAN EVOLUTION
one of these factors is Natural Selection,
All organisms have reactions to their environment, and/or, their environment has a huge effect on an organism. Naturally, Africans live closest to the equator, or the middle of the earth's surface. Meaning they have been living there with the heat and the sun's light focused on them. And by the amount of years that have passed, to adapt to their environment, their bodies may have developed dark skin, and dark skin is less likely to get sunburned and to have skin cancer.
Hope it helped! :)))