BTT freeze after 2 use of Apple script

I have created a button which rotates my external display using apple script. And after 2 uses of the button BTT completely freeze. Still visible on Touch Bar, but not responding nor responding in the menubar. Does the script contains any possible errors?
I have tried multiple restarts of macbook, BTT.

Using:
MacBook Pro (15-inch, 2018), 2,2 GHz 6-Core Intel Core i7, 16 GB 2400 MHz DDR4, Radeon Pro 555X 4 GB & Intel UHD Graphics 630 1536 MB.
BTT 3.402

Script
tell application "System Preferences"
set current pane to pane "com.apple.preference.displays"
end tell
tell application "System Events"
tell process "System Preferences"
tell window "DELL U2721DE"
tell pop up button 1 of tab group 1
click
set V to value
if V is "Standard" then
pick menu item "270°" of menu 1
else
pick menu item "Standard" of menu 1
end if
end tell
repeat until exists sheet 1
delay 0.2
end repeat
click button 1 of sheet 1
end tell
end tell
end tell
tell application "System Preferences" to quit