Motor and transistor

I think you'll need to turn that PWM into an actual DC voltage before feeding it into the transistor. You'll just need a simple RC low pass filter for this