ProfileService Fails to Load for Small Percentage of My Players

In my game, I use ProfileService. It’s been far more reliable than using ROBLOX’s default DataStores.

However, there has been an issue that, at lowest, affects a fraction of a percent of players, or at worst, affects upwards of 2% of players. Recently, it’s been closer to 2%, as seen with the numbers below:


It’s a pretty small percentage, but the effects of ProfileService not loading in, are pretty severe. Players won’t be able to claim a base, and their stats will never load - they are stuck in a weird limbo
image

I have a very difficult time trying to replicate this error, as it is pretty rare, and happens at random. The error usually goes something like ServerScriptService.profileService.ProfileService:1738: [ProfileService]: Profile [Store:"PlayerProfile";Key:"Player_UserIdHere"] is already loaded in this session, which is weird, since in the above affected individual’s case, he had not played the game in a few months, so there should be no session locking happening anywhere else.

In the actual ProfileService script, these are the line(s) it is referencing:

for _, profile_store in ipairs(ActiveProfileStores) do
		if profile_store._profile_store_lookup == self._profile_store_lookup then
			local loaded_profiles = is_user_mock == true and profile_store._mock_loaded_profiles or profile_store._loaded_profiles
			if loaded_profiles[profile_key] ~= nil then
---- the below error statement is the line that gets printed
				error("[ProfileService]: Profile " .. IdentifyProfile(self._profile_store_name, self._profile_store_scope, profile_key) .. " is already loaded in this session")
				-- Are you using Profile:Release() properly?
			end
		end
	end

The only line(s) of code I have going that reference Releasing a profile are the below:

function PlayerDataHandler:playerAdded(player)
	local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
	
	if profile then
		profile:AddUserId(player.UserId)
		profile:Reconcile()
		
		profile:ListenToRelease(function()
			Profiles[player] = nil
			
			player:Kick("To protect your data, you were kicked from the game.")
		end)
		
		if not player:IsDescendantOf(Players) then
			profile:Release()
		else
			Profiles[player] = profile
		end
	else
		player:Kick("There was an error loading your data, and for your protection, you were kicked from the game. Please try again!")
		--logger.dataFail(player,"Data did not load correctly upon joining")
	end
end

function PlayerDataHandler:Leaving(player)
	if Profiles[player] then
		Profiles[player]:Release()
	end
end

function PlayerDataHandler:Init()
	game.Players.PlayerRemoving:Connect(function(player)
		if Profiles[player] then
			Profiles[player]:Release()
		end
	end)
end

PlayerDataHandler:Init() never gets called, it is something I forgot to remove, but I do not think it is the issue here. PlayerDataHandler:Leaving is actually what gets called by the main leaderboard script when a player leaves the game.

Does anyone know how to fix this? I inquired about this before on a different post, but the answer I received there clearly has not been the long-term solution.

2 Likes

BUMP’ing this thread, since no one responded, and the issue still occurs.

1 Like

BUMP’ing this again. It seems to occur most frequently when a player gets disconnected from the game due to internet or other issues and rejoins.

1 Like

I don’t know the system very well. This seems like a problem that requires you to be familiar with the ProfileService code. I can only give you general advice for dealing with difficult/specialized bugs.

I would recommend to do the following:

  • contact the developer of ProfileService to see if you can get some type specialized help, try DMing here on devforum and see if you get a response
  • if that’s not possible, ask inside the resource post itself or search around to see if anyone has this problem (from doing a quick look there are already two users who mention this problem in the the for that module: Save your player data with ProfileService! (DataStore Module) - #154 by QWEESPY_DEV, Save your player data with ProfileService! (DataStore Module) - #1155 by NotRapidV)
  • contact those developers with the same problem to see if they have any more information
  • ask your players/community to give you more information, sometimes they tend to leave out important stuff since they don’t know what’s important and what’s not
  • make sure your ProfileService module is updated to the newest version, someone may have reported that issue and a patched release may already exist
  • if there’s no solution so far, you’ll just have dig into the code yourself
  • if all else fails, you’ll probably have to move to a different system

Hope this helps, good luck!

Thanks for the help, but I was hoping this post would get more attention than DM’ing a random big ROBLOX dev for help

There is a small chance that ProfileService may not release the Profile correctly, I reommend you “ForceLoad” the players Profile, like this

local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId, "ForceLoad")

In this case the player profile will forcefully load the player’s data even with the session already loaded

You can try my method, but I can’t guarantee that it is a 100% way to solve your problem

1 Like

clearly an issue with releasing the profile
add prints to check if it really releases and try to replicate the error

Except that in most cases, affected players have not played the game in a number of hours/days.

Have you used this method before? To what success? In addition, I know in ProfileService, it’s frowned upon to “ForceLoad” profiles, so I am curious as to what the worst case scenario with that enabled would be…

Yes, the success is to load players profile even if they have a session locked in another roblox server which the problem here is that some players have sessions locked in dead servers, it’s frowned because you need to end locked sessions in the correct method which is release but I can give you another method if you are not sure about this one:

Stealing players profile from dead sessions
As ProfileService API says, you can use “Steal” to get players profile almost inmediatly and also will create a new session lock in this server and it will ignore the other “dead” session lock

local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId, "Steal")

This method will work better for you, do a couple of test with this 2 methods before trying it in your actual game if you are still unsure and choose the best for you

Well, testing this isn’t exactly easy, since the issue is pretty rare to begin with. But I will try this!

1 Like

Ok, so it’s been nearly two weeks since I added this to my game.

The glitch still occurs, albeit it has been getting lower.

Of those 233 results, there were only about 128 unique instances, or about 1% of the 10,000 DAUs. Some of those instances were the result of a player joining and rejoining, trying to fix the glitch. The glitch usually fixes itself after some time, but by then I’d imagine afflicted players would give up and move onto something else, which is obviously not good from a developer perspective.

From my experience, this usually happens to players when their game crashes/disconnects, which I have a separate topic on, and then try to rejoin a new server. It doesn’t make sense that, if their session from the disconnected server is still “locked,” that ProfileService will be throwing an error message about the profile already being loaded in the new session.

I don’t think “Steal” will really help here, since I don’t think “Steal” is going to steal from the session it is currently in. Would running a pcall() function every time I try pulling stats from ProfileService, detecting if it failed, if it did, release the profile, and then re-try initializing work?

Ok, so I found a potential source of the issue:
image

I have this in case players load before scripts load. When players join the game after scripts load, the for loop should not be detecting and picking them up - is there a chance that players are getting loaded twice?

I found the issue, and I think I finally solved it for good. See the attached posting below:
Need Help Debugging a HUGE ProfileService Error - Help and Feedback / Scripting Support - Developer Forum | Roblox

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.