LoadCharacter is slow

Hello. On my game, I have gotten numerous reports from players regarding slow loading times. After narrowing down the game’s loading process, I noticed that LoadCharacter was taking the majority of the time by setting up benchmarks.

local bench1 = os.clock();
plr:LoadCharacter();
local bench2 = os.clock();
print(bench2 - bench1);

The time between benchmarks is erratic, taking anywhere from 0.3 to 15 seconds, even 10-25 minutes according to one report. This only seems to happen when the player first joins the game; characters respawn at a normal pace afterward. Is there anything I can do about this? Is this a problem with server resource management or is Roblox just being slow? Any help is appreciated.

1 Like

Is CharacterAutoLoads disabled? I assume there’s a long yield between the PlayerAdded signal firing for the player and the instance method :LoadCharacter() being called for whatever reason.

Would you be able to provide the relevant section of code?

1 Like

CharacterAutoLoads is disabled as I use a custom respawn method.

function PlayerData:Respawn(respawnTimer)
    
    local plr : Player = self.Player;
    if not plr then return end

    if (type(respawnTimer) == "number" and respawnTimer > 0) then
        task.wait(respawnTimer);
    end

    -- benchmark start
    plr:LoadCharacter();
    -- benchmark end

    -- Set collision group for character
    local char = plr.Character or plr.CharacterAdded:Wait();
    local partsToWaitFor = {"HumanoidRootPart", "UpperTorso", "LowerTorso"};
	for _, name in pairs(partsToWaitFor) do
		local part = char:WaitForChild(name);
		PS:SetPartCollisionGroup(part, "Player");
	end

end

Maybe it’s because I’m using CharacterAdded:Wait()? Not sure though, since the delay seems to be taking place solely in the LoadCharacter method.

1 Like

Hi Sham, I use LoadCharacter() and I am experiencing a very similar problem. I setup print statement before and after the method.

Most of the time when playing in servers it is very quick, roughly <1 second. However, it does occasionally yield forever for some players. I understand it is a yielding function but it’s really annoying that some players are not even able to play my game when they join because of this issue.

Did you eventually find a solution to your problem? It may be helpful in my case as well.

1 Like

Sorry, it’s been quite a while since I created this topic so I don’t remember the exact details. But if I had to guess, it might’ve had something to do with preloading too many assets via ContentProvider? My issue only occurred before spawning in for the first time; respawning worked as normal thereafter. If your case is the same, I suggest temporarily disabling portions of code that may slow down join times, especially if you are preloading anything.

1 Like

i’ve been encountering this too, we haven’t been able to track it down to anything specific which makes me think it might be something to do with roblox backend.

1 Like