To get to the Stanserhorn, you can first take the train from Lucerne to Stans. In Stans, it is about a five-minute walk to the Stanserhorn railway. First you take the historic funicular railway for about 10 minutes. At the middle station, change to the CabriO cable car and travel all the way up to the Stanserhorn in about 10 minutes.
If the weather is fine and in high season, it is advisable to make a reservation. You can easily buy your boarding pass online here.