Can't figure out how to use pwm with an optocoupler and a MOSFET

The circuit is correct, if you don't have parts yet make sure you get an n-channel part.