Why does this ProfileService error happen?

This happens to a small subset of players in my games that use ProfileService. I have not been able to find other threads (not made by me) that discuss this issue + how to resolve it.

Associated codes at lines mentioned:

--- player data handler module
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
			player:SetAttribute("init",true)
		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

---ProfileService script
-- Check if profile with profile_key isn't already loaded in this session:
	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
				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

Does anyone know how to fix this?

Guessing …
Attempting not to load the same profile multiple times.

-- player data handler module
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
			player:SetAttribute("init",true)
		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

-- ProfileService script
-- Check if profile with profile_key isn't already loaded in this session:
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
			warn("[ProfileService]: Profile " .. IdentifyProfile(self._profile_store_name, self._profile_store_scope, profile_key) .. " is already loaded in this session")
			return -- or do something else to handle this case
		end
	end
end

But what is the solution? The code you posted is the exact same as mine.

if loaded_profiles[profile_key] ~= nil then
    warn("[ProfileService]: Profile " .. IdentifyProfile(self._profile_store_name, self._profile_store_scope, profile_key) .. " is already loaded in this session")
    return -- or do something else to handle this case
end

this is different

try not to load the same profile multiple times (if you are doing this), maybe this is causing the error or it is probably just an internal ProfileService error

what is the objetive of this change? the error function already stop the script

To not reload the profile multiple times.
Just guessing as I can’t test this.

I believe the problem is multiple profile loads. That code may or may not fix that.

ah, I see. Honestly, I think it would be best to make it kick the player and release the profile, how would I do that from just having the player ID?

I would think just kicking them would release anything tied to them. Maybe a = nil also.

Is there a way to avoid this, period?

What kicking them? I was hoping that post was it to avoid that.
I have a game that puts on a custom outfit on logging in, if it doesn’t work out they get kicked. Sad fix, but it works.

No, I mean is there a way to avoid the issue of the Profiles not loading happening? I’ve calculated that at worst, it happens <1% of the time, but it’s still an issue.

You are deeper into ProfileService than I’ve tried myself. Maybe someone else will know …
If it’s <1% … I’d kick em (just on hacker suspecting alone).

If this IS only on load up.

Same thing is happening to my game man. No idea how to fix it. If you fixed it, can you perhaps share with me how? Or are you still clueless as me?

You probably aren’t releasing it right, like seen in this post where I found my solution:
Need Help Debugging a HUGE ProfileService Error - Help and Feedback / Scripting Support - Developer Forum | Roblox

Whenever a player leaves the game, you MUST release their profile immediately - there can be no ands ifs or buts about that. I found that some players, when attempting to join the game, would repeatedly be joined in and then booted out a few times over due to their connection and how ROBLOX works (I think) so if the release statement isn’t unabated it would cause issue.