ProfileService Load Times Randomly Spiked

I don’t even know where to begin with this post because I know I sound like a conspiracy theorist, but I made a little simulator game over the past few months and at the beginning of May the load times launched from 4-8 seconds up to 60-90 seconds minimum without anything in-game being changed or adjusted by me.

I’m using ProfileService for my Player Data, and as far as I can tell everything should be working as intended. I’ve tried following this guide which implies that my issue has something to do with an unreleased Profile (which should not be the case),

I’m not really sure where else to go with this. I have truly done everything I can think of, please please please somebody tell me you’ve had this issue before and you know how to solve it before I rip my eyeballs out.

Server-side Data Script:

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Template = require(ReplicatedStorage.PlayerData.Template)
local Manager = require(ServerScriptService.PlayerData.Manager)
local ProfileService = require(ServerScriptService.Libs.ProfileService)

local ProfileStore = ProfileService.GetProfileStore("SkylandsReleaseData", Template)

local KICK_MESSAGE = "Data issue, try again momentarily."

local function CreateLeaderStats(player: Player)
	local profile = Manager.Profiles[player]
	if not profile then return end
	
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local coins = Instance.new("NumberValue", leaderstats)
	coins.Name = "Coins"
	coins.Value = profile.Data.Coins
	
	local gems = Instance.new("NumberValue", leaderstats)
	gems.Name = "Gems"
	gems.Value = profile.Data.Gems
	
	local ascensions = Instance.new("NumberValue", leaderstats)
	ascensions.Name = "Ascensions"
	ascensions.Value = profile.Data.Ascensions
end

local function LoadProfile(player: Player)
	local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
	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
		CreateLeaderStats(player)
		Manager.ProfileLoaded:Fire(player, profile.Data)
		Manager.GiveBadge(player, "Skylands Novice")
	else
		profile:Release()
	end
end

for _, player in Players:GetPlayers() do
	task.spawn(LoadProfile, player)
end

Players.PlayerAdded:Connect(LoadProfile)
Players.PlayerRemoving:Connect(function(player)
	local profile = Manager.Profiles[player]
	if profile ~= nil then
		print(player.Name .. "'s profile has been released!")
		profile:Release()
	end
end)
1 Like

Just an update because I noticed something silly in my script after posting it. The print statement in my PlayerRemoving connection was before the profile actually released, but I have fixed that now, and the statement still prints properly.

image
image

I’ve made 2 small adjustments here, shown in comments. No noticeable change in load-time.

Not sure if you still need help, but I had a similar issue and just solved it here

1 Like

I’ll mark this as a solution because it absolutely would have worked. I did find out what the issue was eventually and forgot to update this post.

The game had a leaderboard script that for some reason was running before individual players had their data loaded in, so it essentially just deferred profile loading on new servers (which all studio test sessions are) until 300 other profiles had been loaded and assigned to the leaderboard part.

I ended up doing something similar, but instead of a boolean variable, I just removed the task.spawn for the leaderboards and had the profileLoaded event of the first player joining the server start the leaderboard script after loading. Kinda janky but it worked.

1 Like