Skip to content

Commit e541b06

Browse files
PlayerRemoving needs to pass in userId
1 parent d189f55 commit e541b06

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/datastore/src/Server/PlayerDataStoreManager.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ export type PlayerDataStoreManager =
8383
_disableSavingInStudio: boolean?,
8484
},
8585
{} :: typeof({ __index = PlayerDataStoreManager })
86-
))
87-
& BaseObject.BaseObject
86+
))
87+
& BaseObject.BaseObject
8888

8989
--[=[
9090
Constructs a new PlayerDataStoreManager.
@@ -111,7 +111,7 @@ function PlayerDataStoreManager.new(
111111
self._maid._savingConns = Maid.new()
112112

113113
self._datastores = {} -- [userId] = datastore
114-
self._removing = {} -- [player] = true
114+
self._removing = {} -- [userId] = true
115115
self._pendingSaves = PendingPromiseTracker.new()
116116
self._removingCallbacks = {} -- [func, ...]
117117

@@ -120,7 +120,7 @@ function PlayerDataStoreManager.new(
120120
return
121121
end
122122

123-
self:_removePlayerDataStore(player)
123+
self:_removePlayerDataStore(player.UserId)
124124
end))
125125

126126
if skipBindingToClose ~= true then
@@ -286,18 +286,20 @@ function PlayerDataStoreManager._removePlayerDataStore(self: PlayerDataStoreMana
286286
end
287287
end
288288

289-
PromiseUtils.all(removingPromises)
289+
local closePromise = PromiseUtils.all(removingPromises)
290290
:Then(function()
291291
return datastore:SaveAndCloseSession()
292292
end)
293293
:Finally(function()
294294
datastore:Destroy()
295+
self._maid._savingConns[userId] = nil
295296
self._removing[userId] = nil
296297
end)
297298

299+
self._pendingSaves:Add(closePromise)
300+
298301
-- Prevent double removal or additional issues
299302
self._datastores[userId] = nil
300-
self._maid._savingConns[userId] = nil
301303
end
302304

303305
function PlayerDataStoreManager._getKey(self: PlayerDataStoreManager, playerOrUserId: Player | PlayerUserId): string

0 commit comments

Comments
 (0)