title: Why is the LockService is not working as intended?
body: <p>I'm having a problem with the same entry begin saved multiple times and I realized it was mostly caused by double clicking. I'm trying to use LockService to avoid it: if the lock is not aquired in a millisecond the script should be aborted(because it's a duplicated operation).</p>
  <pre><code>//more code above
  var lock = LockService.getScriptLock();
  try{
    lock.waitLock(1);//get the lock timing out in 1 millisecond 
    SpreadsheetApp.flush();
    ss.insertRowBefore(6);
    ss.getRange(&quot;A6&quot;).setValue(data[0][0]);
    ss.getRange(&quot;B6&quot;).setValue(formatedString);
    ss.getRange(&quot;C6&quot;).setValue(data[1][0]);
    ss.getRange(&quot;D6&quot;).setValue(data[2][0]);
    ss.getRange(&quot;E6&quot;).setValue(data[3][0]);
    ss.getRange(&quot;F6&quot;).setValue(data[ref][0]);
    SpreadsheetApp.flush();
    Utilities.sleep(10);//This is to make sure it takes at least 1 millisecond 
  }
  catch(e){
    return;//It should generate a exception and end the script if the lock is not aquired
  }
  //more code bellow
  </code></pre>
  <p>The problem is that I still getting duplicated entries(tougth only 2 most of the time, so I believe it's working in part). What I am doing wrong?</p>