Membership of Historic Environment Scotland (HES) and/or the National Trust for Scotland (NTS) is worth considering, especially if you're going to be in Scotland for a while. Both are organisations dedicated to the preservation of the environment, and both care for hundreds of spectacular sites. You can join up at any of their properties.
Historic Environment Scotland This organisation cares for hundreds of sites of historical importance. An annual membership costs £55/101 per adult/family, and gives free entry to HES sites (half-price entry to sites in England and Wales). Also offers a short-term Explorer Pass – three days out of five for £31, or seven days out of 14 for £42. It can be great value, particularly if you visit both Edinburgh and Stirling castles.
National Trust for Scotland Looks after hundreds of sites of historical, architectural or environmental importance. An annual membership, costing £57/102 for an adult/family, offers free access to all NTS and National Trust properties (in the rest of the UK). If you're 25 or under, it's a great deal at only £26.
If travelling on a budget, membership of the Scottish Youth Hostels Association is a must.
Discount cards for those over 60 years are available for train travel.
Student Youth Cards
The most useful card is the International Student Identity Card (www.isic.org), which displays your photo. This gives you discounted entry to many attractions and on many forms of transport.