Help with a strange issue

I’ll start by saying I am by no means a mechanic. I’ve got a 2002 Polaris Sportsman 500 HO. Today it’s 20 outside and we got snow so I was going to pull the kids on a sled. When I started and ran it for about 20 minutes it all the sudden cut off. When I tried to start it back up it did start and ran for about 5 seconds before cutting off again (I checked the fuel switch and it’s on). When I tried to restart it again you can hear the start turn but I don’t think I’m getting spark or compression. I tried turning it over a couple more times and could hear it hit one time. I was going to pull it back to the house and got the truck which took me about 10 minutes. Before connecting the tow strap I gave it another try and it started and I drove it back up to the house. The problem seems to happen when the 4wheeler gets warm and then it doesn’t seem to get spark.

I figured I would start hear before pulling the plug to see if there were any signs of damage. Any ideas??