Derek Mackay started the week as Scotland’s powerful finance secretary who has long been tipped to be the country’s next leader. On Thursday, he was due to deliver a showpiece budget statement and further solidify his position as next-in-line—and possibly as the man to lead Scotland to independence in the wake of Brexit.

Instead, his career lies in ruins after it was revealed he sent hundreds of “predatory” texts to a 16-year-old schoolboy.

Mackay, one of the most recognizable lawmakers from the pro-independence Scottish National Party, has admitted he “behaved foolishly” and has submitted his resignation to First Minister and party leader Nicola Sturgeon. He was left with no other option after the Scottish Sun exposed screens of text messages, including one telling the unnamed boy he was “really cute” and inviting him to dinner and a rugby match with him.

The transcripts show Mackay repeatedly messaged the boy on a number of platforms for six months, despite some responses from the teenager in which he clearly expressed his discomfort. Mackay reportedly contacted the boy after having had no prior contact, and kept messaging him even after the teen revealed he was just 16 and told Mackay not to “try anything.”

In the most damning part of the transcript, Mackay asked the boy, “And our chats are between us?” before following up with: “Cool, to be honest I think you are really cute,” then encouraging him to delete the message.

In all, Mackay sent 270 messages to the schoolboy. The lawmaker complimented the boy’s haircut, informed him of his sexuality, and invited the kid to be his guest at an official parliamentary rugby event. Mackay also messaged the boy on Christmas Day, sending a number of messages, including one just before midnight that said: “You still up.”

The creepy messages were publicly exposed after the boy’s mother learned what was happening and told the newspaper. She told the Scottish Sun: “If I could speak to [Mackay], I would ask him ‘Why? Why did you do this?’ I worry about what would have happened if my son had sent him back a message he wanted to hear. You can see he tries again and again—like he is trying to get my son to change his mind about something.”

Following the report, Mackay apologized to the boy’s family and resigned.

In a statement to ` Scotland’s devolved parliament on Thursday, Sturgeon confirmed that she’d accepted Mackay’s resignation from her government, and said that he has also been suspended by the party while it carries out further investigations. However, he remains a member of the Scottish parliament—a fact that provoked fury from opposition leaders.

Scottish Conservative party leader Jackson Carlaw said that, not only should Mackay stand down from the parliament, his messages could “constitute the grooming of a young individual.” Scottish Labour leader Richard Leonard said Mackay “abused his power,” calling his actions “predatory.”

The scandal has rocked the Scottish National Party and Scotland’s devolved government at a pivotal time. It’s pushing for another referendum on Scottish independence following Britain’s withdrawal from the European Union last week. In the 2016 referendum on Europe, Scottish voters overwhelmingly backed remaining inside the EU, and recent polling has suggested that Brexit has boosted support for independence.

It also comes ahead of the trial of Alex Salmond, the country’s former first minister, who for decades led the campaign for Scottish independence. He was charged last year with two counts of attempted rape and several counts of sexual assault. That trial is set to begin in March.