ProfileService LoadProfileAsync() taking a full minute to load

When I migrate servers to a new update and sometimes when joining a new server, for some reason, ProfileStore:LoadProfileAsync has started to take a full minute to load. The first print here fires as the player joins, but the print("TEST1") doesn’t fire until a full minute after the first print.

local function PlayerAdded(player: Player)
	print("TEST")
	local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId.."_Save5")
	print("TEST1")
	if not profile then player:Kick(KICK_MESSAGE) return end
	profile:AddUserId(player.UserId)
	profile:Reconcile()
	profile:ListenToRelease(function()
		Manager.Profiles[player] = nil
		player:Kick(KICK_MESSAGE)
	end)
	
	if player:IsDescendantOf(Players) == true then
		Manager.Profiles[player] = profile
		CreateDataFolder(player)
	else
		profile:Release()
	end
end

This has only recently started happening in my game. I am not too familiar with how ProfileService works so I don’t know what would cause it to take so long to load.

Could it be that there’s just too much data? I do have about 50 different variables in my Template script for ProfileService. But it’s weird that before today it didn’t take any extra time to load at all.

1 Like

This issue is likely due to the way you handle releasing the profiles when the server crashes/restarts. Do you have logic similar to the code below that attempts to release everyone’s profile when the server is about to close?

game.Players.PlayerRemoving:Connect(function(player: Player)
    if Manager.Profiles[player] then
        Manager.Profiles[player]:Release()
        Manager.Profiles[player] = nil
    end
end)

game:BindToClose(function()
    for _, profile in Manager.Profiles do
        profile:Release()
    end
end)
1 Like

I had the first connection that you sent, but even after adding the second the issue still persists

Ok so I’m not sure why this fixed my problem, but it did. I had my data script create a BoolValue and parent it to each player when they join called hasLoaded. I set it to true after the profile loaded, and stopped my other scripts from doing anything until hasLoaded == true.

local function PlayerAdded(player: Player)
	local hasLoaded = Instance.new("BoolValue")
	hasLoaded.Name = "hasLoaded"
	hasLoaded.Value = false
	hasLoaded.Parent = player
	
	local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId.."_Save5")
	
	hasLoaded.Value = true

	if not profile then player:Kick(KICK_MESSAGE) return end
	profile:AddUserId(player.UserId)
	profile:Reconcile()
	profile:ListenToRelease(function()
		Manager.Profiles[player] = nil
		player:Kick(KICK_MESSAGE)
	end)
	
	if player:IsDescendantOf(Players) == true then
		Manager.Profiles[player] = profile
		CreateDataFolder(player)
	else
		profile:Release()
	end
end

And here’s the script where I manage all of my client scripts:

local player = game.Players.LocalPlayer
local hasLoaded = player:WaitForChild("hasLoaded")

while hasLoaded.Value == false do
	task.wait(1)
end

-- Variables for my scripts and calls to their start functions

After doing this, the load times are basically instantaneous again.

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