Need Help Debugging a HUGE ProfileService Error

I have made numerous topics on this issue before, like this one.

I have had no luck. I decided to put warn statements around me code (so they would be easy to find in Error Report under Monitoring), in and around the code that initializes the profile service stuff. I am even more confused.

The below is a screenshot from Error Report:


(ReplicatedStorage.profileServiceConnection pulls data from ServerScriptService.profileService.PlayerDataHandler which pulls the actual ProfileService stuff, it is a little screwy how that works but that setup is not the issue FYI)

As you can see, Line 154 in the leaderBoard script gets executed - but there is a line of code before that, that is supposed to serve as a ‘checkpoint’ to see how things are going - and that code is never fired before ProfileService gets initialized… Example:

if loadedFromLoop == true then
		warn(Player.UserId.." was loaded from the for loop!")
	else
		warn(Player.UserId.." was loaded normally.!")
	end
	warn(Player.UserId.."'s Parent is "..tostring(Player.Parent))
	psConnection:PlayerAdded(Player)

Sometimes, however, it does get fired and prints the above warn statements:

It seems like in the above scenario, the affected player joined and rejoined 5 times, the first times nothing worked, and the fifth and final time, ProfileService loaded correctly.

I have no idea why this happening. for the code that actually pulls data from ProfileService, this is that “playerAdded” function:

function PlayerDataHandler:playerAdded(player:Player)
	local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId, "Steal")
	
	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()
			warn(player.UserId.." has not really loaded in yet...")
		else
			Profiles[player] = profile
			if player:GetAttribute("initialized") ~= true then
				player:SetAttribute("initialized",true)
			else
				warn(player.UserId.." has already been loaded in once before...")
			end
		end
	else
		player:Kick("There was an error loading your data, and for your protection, you were kicked from the game. Please try again!")
	end
end

In the above code, if the code detects that the player was loaded already, it would detect that “initialized” attribute and warn about it. There is no instance of that happening, whatsoever.

I am very confused as to how this is even happening with ProfileService. I used a similar setup in a different game when I was actively working on it (I am no longer), and I did not have nearly a fraction of the issues I’ve had using ProfileService in this game.

Can anyone help me figure out what the hell is going on here???

I’m getting frustrated trying to solve this. Should I just do a pcall() in PlayerDataHandler:playerAdded(), if it fails, release the profile, and then try establishing connection again?

Well, I found the solution to this issue I think.

Before, the code was structured like this:


function saveStats(plr)
	--- save stats here
end

function playerAdded(plr)
	profileService:Init()
	
	game.Players.PlayerRemoving(function(p)
		if plr == p and vipServer == false then
			saveStats(plr)
			profileService:Release()
		end
	end)
end

As you can see, the vipServer == false bit caused big issues. Removing that fixed 90% of the problem, or having profileService release outside of that if statement, but it still happened occassionally.

Moving the player removed connection from inside the player added function to outside in the script normally finally fixed the issue for good.