I’m using ProfileService and I seem to randomly get this error:
It occurs whenever a player joins, but seems to only happen maybe 1 in 50 tries. I cannot reliably reproduce the problem. Its a major problem as it simply does not let some new players play the game at all and they think it is broken, thereby leaving a negative impression on them.
Also worth noting, a player can join, experience this issue, make no changes, and rejoin and it will work fine.
Below is a code snippet for when a player joins and how I set up their data/profile. Maybe I am doing something wrong with implementation?
local function playerAdded(player)
local profile = ProfileStore:LoadProfileAsync('Player_'..player.UserId)
if (profile) then
if not profile.Data['Buildings'] then
profile.Data = decompressData(profile.Data)
end
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
local plrData = Profiles[player].profile.Data
print(plrData)
local asStr = Http:JSONEncode(plrData)
print(#asStr)
Profiles[player] = nil
if (script.ProfilesLoaded:FindFirstChild(player.UserId)) then
script.ProfilesLoaded:FindFirstChild(player.UserId):Destroy()
end
player:Kick()
end)
if not (player:IsDescendantOf(plrs)) then
profile:Release()
else
local leaderstatsFolder = Instance.new('Folder')
leaderstatsFolder.Name = 'leaderstats'
leaderstatsFolder.Parent = player
Profiles[player] =
{
profile = profile,
leaderstats = leaderstatsFolder
}
local cashStat = Instance.new('StringValue')
cashStat.Name = 'Cash'
cashStat.Value = Common.shortCash(math.floor(profile.Data.Cash))
cashStat.Parent = leaderstatsFolder
local blocksMinedStat = Instance.new('IntValue')
blocksMinedStat.Name = 'Blocks Mined'
blocksMinedStat.Value = profile.Data.BlocksMined
blocksMinedStat.Parent = leaderstatsFolder
local val = Instance.new('StringValue')
val.Name = player.UserId
val.Parent = script.ProfilesLoaded
script.Listener.Update:Fire(player, 'ResourcesDiscovered', profile.Data.ResourcesDiscovered)
end
else
player:Kick()
end
end
game.Players.PlayerAdded:Connect(playerAdded)