I'm going in three weeks so I've been studying this stuff.
Basically, you need to get a "boarding group" if you want to ride. They run out within the first minute of the park opening time.
1) Be in the park before it opens. Tickets scanned in before opening time.
2) Click the right button in the official Disneyland app at the exact moment of opening.
3) Use the force.
Details here. And the details matter. The above two steps aren't enough.
This site is the most comprehensive strategy guide I've seen:
Here is another guide which may not be as accurate.