Background: Problem-solving followed by instruction (PS-I) is a powerful design shown to transform students' conceptual understanding and transfer. Within PS-I, no research has examined how momentby-moment determinants of affective states impact the problem-solving phase and posttest performance. Methods: I develop a multimodal learning analytics pipeline to (a) infer affective states in PS-I via observable facial movements, (b) understand how the incidence and temporal dynamics of these states vary based on manipulating the problem-solving context with scaffolding strategies (failure-driven, successdriven, none) in an experimental study (N = 132), and (c) assess the extent to which affective states might explain learning. Findings: Students exposed to failure-driven scaffolding show exclusive dynamics comprising shame, a self-conscious emotion associated with metacognitive and cognitive benefits. Failure-driven scaffolding also creates opportunities for relatively greater emotional displays of knowledge emotions (e.g., surprise, interest). Hostile emotions differentially impact learning in PS-I, with the incidence of anger and disgust showing positive associations and the incidence of contempt showing a negative association. Finally, pleasurable emotions (e.g., happiness) positively associate with isomorphic posttest performance but negatively associate with non-isomorphic and transfer posttests. Contribution: Overt changes in facial movements reflective of students experiencing negative emotional states act as catalysts for learning.