trx500fa transmission help?!?!

I was riding my 2004 Honda foreman rubicon 500 (trx500fa) with hondamatic through a level field behind my house (I wasn’t hammering it or anything. I was being quiet and only going 10 mph) well anyway I was just cruising along and it literally popped out of gear and started to grind. So I put it in neutral real quick. The grinding stopped. I put it back into drive again and it seemed like it wanted to start going but it started grinding again. So I shut it off and pushed it home. the grinding seems to be coming from the transmission area. I think it has to do with the drive chain inside next to the cam chain. I just recently (last week) rebuilt the top end due to valve problems. the motor itself runs perfect and sounds perfect. I was just riding it a little when the above story happened. Any ideas what happened or what I need to look at to fix it? My friends dad know all about fixing engines and he has no idea. but he’s is going to help me fix it once I figure out what it is. the service manual has zero suggestions. So any suggestion or links to solutions or anything will help! Thanks!!! feel free to ask any questions or message me