Oxygen has atomic number 8 so the electron configuration is 1 s2 2 s2 and 2 p4, so oxygen has 2 single electrons, its meant that oxygen only has 2 valence. Its different with sulfur that has atomic number 16, The electrons configuration 1 s2 2 s2 2 p4 3 s2 and 3 p4, its look like oxygen configuration, but remember that in M shell not only s and p but there are d orbital. So, the electron couple electron from 3p can promote to the 3d. and now sulfur has four single electrons and has valence 4.