How do you score this instance in pegging?

Had an interesting lay of cards during pegging with 4 players. I was wondering how one would score this:

P1: lays down 7
P2: follows with a 4
P3: plays a 3
P4: makes a run for three points with a 2
P1: then plays a 6
P2: places down a 5... does this complete any runs for any points?

6 card run

While they are played in a disjointed order these cards: 2,3,4,5,6,7 constitute a 6 card run. Never seen that one before. Congratulations.

More than 1 run

Please also note that the 4, 3, 2 is also a run that P4 should have taken. P2 also does get a run for 6, and if P1 had an Ace lurking back there, they could have nailed it for even 7 points.

Pegging double tripple

Scoring help.

P1. 6
P2. 5
P3. 4
P1. 3
P2. 5
P3. 5
P1. 3

We scored it as 40, is that correct?

no it is not correct. Played

no it is not correct. Played in order, 6543 pegged 4 points - 435 pegged 3 points - 55 pegged 2. Final 3 pegged 2 points for 31. The Double Run/Triple Run does not peg in the play of the hand.

Not sure

Not sure who you are keeping score for so lets break it down shall we?
P1 zero
P2 zero
P3 15 for 5
P1 18 for 4
P2 23 for 3
P3 28 for 2
P1 31 for 2

The total points scored during this round are P3 gets 7, P1 gets 6 and P2 gets 3. 16 total points pegged. Not sure where you came up with 40? Were you trying to score your hands while pegging? Pegging is a distinct action BEFORE counting your hands. It is NOT included at the same time.