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
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.