diff --git a/server/src/services/maproom/v2/leaveWorld.ts b/server/src/services/maproom/v2/leaveWorld.ts index b8dd66c0..3eefd1c3 100644 --- a/server/src/services/maproom/v2/leaveWorld.ts +++ b/server/src/services/maproom/v2/leaveWorld.ts @@ -17,8 +17,11 @@ import { ORMContext } from "../../../server"; export const leaveWorld = async (user: User, save: Save) => { const world = await ORMContext.em.findOne(World, { uuid: save.worldid }); - // Decrement the player count - world.playerCount -= 1; + if (world) { + // Decrement the player count + world.playerCount -= 1; + await ORMContext.em.persistAndFlush(world); + } // Reset the user's save data save.worldid = null; @@ -31,7 +34,7 @@ export const leaveWorld = async (user: User, save: Save) => { // Remove user's cells from the world await removeUserCells(user); - await ORMContext.em.persistAndFlush([world, save, user]); + await ORMContext.em.persistAndFlush([save, user]); }; const removeUserCells = async (user: User) => {