Complex sentence: Dwight receives a "gaydar" machine from Jim (really a metal detector), testing it first on Oscar, but shocked when it beeps as he inadvertently swipes it across his own belt buckle.
Split into simpler sentences: Dwight receives a "gaydar" machine from Jim (really a metal detector). He tests it first on Oscar, and, later, is shocked when it beeps as he inadvertently swipes it across his own belt buckle.