Scotland is not a member of The E.U.  The United Kingdom is.  If Scotland voted independent while The U.K. departure is still pending then, as a new nation, Scotland would have to apply for E.U. Membership and join the queue behind Turkey and several others.  If, after actual U.K. departure Scotland broke away the same prevails.  New nation; new application process.  There are no rabbits in the hat.  On the plus side, I look forward to seeing the refurbished Hadrian's Wall and the customs and immigration stations it will entail.  The Romans had a little something on the ball when they walled out the barbarians and, fortunately, they built to last!