error "System Events got an error: Can’t get application process \"System Preferences\"." When running 
tell application "System Events"
    click button "Turn Bluetooth Off" of window 1 of application process "System Preferences"
end tell

I get the error:
error "System Events got an error: Can’t get application process \"System Preferences\"." number -1728 from application process "System Preferences”

I’ve also tried 
tell application "System Preferences"
    reveal pane "com.apple.preferences.Bluetooth"
end tell
tell application "System Events" to tell process "System Preferences"
    click button 6 of window 1
end tell
quit application "System Preferences”
Didn’t give me any errors, but it didn’t work

I’m running macOS Sierra. This is supposed to turn my bluetooth off (I’m planning to have this run when I login)
This works for me using the latest version of macOS Mojave.  This code may need to be adjusted To work with the current version of your operating system;

try
    if application "System Preferences" is running then do shell script "killall 'System Preferences'"
end try
repeat until application "System Preferences" is not running
    delay 0.1
end repeat
tell application "System Preferences"
    reveal anchor "Main" of pane id "com.apple.preferences.Bluetooth"
end tell

tell application "System Events" to tell application process "System Preferences"
    repeat while not (exists of UI element "Turn Bluetooth Off" of window "Bluetooth")
        delay 0.1
    end repeat
    click UI element "Turn Bluetooth Off" of window "Bluetooth"
    repeat while not (exists of UI element "Turn Bluetooth On" of window "Bluetooth")
        delay 0.1
    end repeat
end tell

try
    if application "System Preferences" is running then do shell script "killall 'System Preferences'"
end try