diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp
index be8f577090..fb7fbe6499 100644
--- a/libraries/entities/src/EntityTree.cpp
+++ b/libraries/entities/src/EntityTree.cpp
@@ -2553,13 +2553,12 @@ bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElementPointer
     }
     entityDescription["DataVersion"] = _persistDataVersion;
     entityDescription["Id"] = _persistID;
-    scriptEngineMutex.lock();
+    const std::lock_guard<std::mutex> scriptLock(scriptEngineMutex);
     RecurseOctreeToMapOperator theOperator(entityDescription, element, scriptEngine.get(), skipDefaultValues,
                                             skipThoseWithBadParents, _myAvatar);
     withReadLock([&] {
         recurseTreeWithOperator(&theOperator);
     });
-    scriptEngineMutex.unlock();
     return true;
 }
 
@@ -2728,11 +2727,12 @@ bool EntityTree::readFromMap(QVariantMap& map, const bool isImport) {
                 " mapped it to parentJointIndex " << entityMap["parentJointIndex"].toInt();
         }
 
-        scriptEngineMutex.lock();
-        ScriptValue entityScriptValue = variantMapToScriptValue(entityMap, *scriptEngine);
         EntityItemProperties properties;
-        EntityItemPropertiesFromScriptValueIgnoreReadOnly(entityScriptValue, properties);
-        scriptEngineMutex.unlock();
+        {
+            const std::lock_guard<std::mutex> scriptLock(scriptEngineMutex);
+            ScriptValue entityScriptValue = variantMapToScriptValue(entityMap, *scriptEngine);
+            EntityItemPropertiesFromScriptValueIgnoreReadOnly(entityScriptValue, properties);
+        }
 
         EntityItemID entityItemID;
         if (entityMap.contains("id")) {
@@ -2881,12 +2881,11 @@ bool EntityTree::readFromMap(QVariantMap& map, const bool isImport) {
 }
 
 bool EntityTree::writeToJSON(QString& jsonString, const OctreeElementPointer& element) {
-    scriptEngineMutex.lock();
+    const std::lock_guard<std::mutex> scriptLock(scriptEngineMutex);
     RecurseOctreeToJSONOperator theOperator(element, scriptEngine.get(), jsonString);
     withReadLock([&] {
         recurseTreeWithOperator(&theOperator);
     });
-    scriptEngineMutex.unlock();
 
     jsonString = theOperator.getJson();
     return true;