ProfileService Datastore 502 error

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)
4 Likes

As it states, it’s an internal error likely due to DataStore services being down, and all we can do is wait for the service to be restored/stabilize.

For the future, I would recommend letting players know via notification (via gui or kicking) in case of an outage that their data has not been loaded and to retry again shortly.

You should look into ProfileStore if this problem still occurs.

See “Saving data which Roblox cannot serialize” in ProfileService docs - I have a feeling that might be your issue as DataStores can be very vague about certain misuses:

https://madstudioroblox.github.io/ProfileService/troubleshooting/#saving-data-which-roblox-cannot-serialize

You should also make sure you’re staying under the 4MB data limit for any DataStore key. If nothing helps, then it might just be a temporary DataStore outage, especially if it hasn’t been happening for a while without changes to your game.