Self-assembly of polypeptides into fibrillar structures can be initiated by planar surfaces that interact favorably with certain residues. Using a coarse-grained model, we systematically studied the folding and adsorption behavior of a β-roll forming polypeptide. We find that there are two different folding pathways depending on the temperature: (i) at low temperature, the polypeptide folds in solution into a β-roll before adsorbing onto the attractive surface; (ii) at higher temperature, the polypeptide first adsorbs in a disordered state and folds while on the surface. The folding temperature increases with increasing attraction as the folded β-roll is stabilized by the surface. Surprisingly, further increasing the attraction lowers the folding temperature again, as strong attraction also stabilizes the adsorbed disordered state, which competes with folding of the polypeptide. Our results suggest that to enhance the folding, one should use a weakly attractive surface. They also explain the recent experimental observation of the nonmonotonic effect of charge on the fibril formation on an oppositely charged surface [C. Charbonneau, ACS Nano 8, 2328 (2014)1936-085110.1021/nn405799t].