Hi. I’ve been having trouble storing player data lately and was hoping I could get some help.
I used the Purchase Handling code from Roblox Code Samples to save and read my Player data, and it worked fine, but today I found a serious problem, it often fails to read the data (it didn’t have this problem before yesterday…) It always reports an error “Error loading player data: SessionLockError”
Store Link:
code:
function PlayerDataServer._onPlayerAddedAsync(player: Player)
local hasErrored = false
local errorType = PlayerDataErrorType.DataStoreError
if dataStoresEnabled then
local key = PlayerDataServer._getKey(player)
-- We need to pass the player's userId into the SessionLockedDataStoreWrapper so it can correctly
-- tag it for compliance reasons when it writes the session lock metadata
local success, result = PlayerDataServer._sessionLockedWrapper:getAsync(key, nil, { player.UserId })
if success then
PlayerDataServer._playerData[player] = (
result or Sift.Dictionary.copyDeep(PlayerDataServer._defaultData)
) :: PlayerData
PlayerDataServer._playerDataSynced[player] =
Sift.Dictionary.copyDeep(PlayerDataServer._playerData[player]) :: PlayerData
else
-- If this is a session lock error, we want to record a different error type so the client
-- can display an alternative message to the user
if result == SessionLockedDataStoreWrapper.sessionLockErrorString then
errorType = PlayerDataErrorType.SessionLocked
end
warn("Error loading player data: " .. tostring(result))
hasErrored = true
end
else
-- If Data Store access is not permitted, we will treat the load as an error
hasErrored = true
end
if hasErrored then
-- If the player's data load has errored - we still want to allow them to play the game with default data
PlayerDataServer._playerData[player] = Sift.Dictionary.copyDeep(PlayerDataServer._defaultData) :: PlayerData
PlayerDataServer._setPlayerDataAsErrored(player, errorType)
else
PlayerDataServer._sendLoadedData(player)
end
end