Controversial legislation that would have made Scotland the first nation in the UK to back assisted dying has been defeated at Holyrood..