Many bacteria grow on surfaces in nature, where they form cell collectives that compete for space. Within these collectives, cells often secrete molecules that benefit surface spreading by, for example, reducing surface tension or promoting filamentous growth. Although we have a detailed understanding of how these molecules are produced, much remains unknown about their role in surface competition. Here we examine sliding motility in Bacillus subtilis and compare how secreted molecules, essential for sliding, affect intraspecific cooperation and competition on a surface. We specifically examine (i) the lipopeptide surfactin, (ii) the hydrophobin protein BslA, and (iii) exopolysaccharides (EPS). We find that these molecules have a distinct effect on surface competition. Whereas surfactin acts like a common good, which is costly to produce and benefits cells throughout the surface, BslA and EPS are cost-free and act locally. Accordingly, surfactin deficient mutants can exploit the wild-type strain in competition for space, while BslA and EPS mutants cannot. Supported by a mathematical model, we show that three factors are important in predicting the outcome of surface competition: the costs of molecule synthesis, the private benefits of molecule production, and the diffusion rate. Our results underscore the intricate extracellular biology that can drive bacterial surface competition.