One of you knows!!

I grabbed a 2 year old, apparently beat to death, trek 24" bike. The frame is super clean, is a 2020 or 2021 24" Trek mtb, that i was going to float to my 6 year old off his 20".

But... it's a 9 speed, np, but after cleaning and trying to set everything, threw cassette attacked to the 9 speed wheel/hub, seems to have a couple middle sprockets that will spin and throw without engaging the hub. The sprocket seems... broken? Is it? Need a new wheel? New hub?

I took apart the wheel and thought I could just tighten something but... yea. That's not it.

One of you k ow that there is a simple fix or that I have to replace everything.

Which is it?