:LoadCharacter() yielding for 10+ seconds in studio

For some reason my :LoadCharacter() is taking 14/20 seconds to finish executing, which is an obnoxiously long and hinders playtesting, it takes around 1sec for LoadCharacter() to finish in a live server,

It only happens in this one place I am working on too, in other places it works fine.
What could the problem be?

1 Like

This happened to me once. I just had to wait some time until it got autofixed.
Check if there’s any function yielding the code (WaitForChild, wait, task.wait, any:Wait, etc) , if so, use coroutines.

If this doesn’t work, you’ll have to wait some time.

When did this happen and how long did you have to wait for it to get fixed?

This happened the same day in the last roblox service disruption. I’m not sure how long this took, maybe 1-3 hours.

The last roblox service disruption was avatars not loading properly, LoadCharacter would still take only 5secs or so, but now it’s taking ages for me, even when I publish the same place to another place, the issue persists.

Yeah, i’m not sure if the service disruption was the cause of this issue. I suggest you to wait some time and re-checking your code. I hope someone know the solution to this issue.

1 Like

Is there a specific script that causes the function to take longer than usual? Check using the Script Performance tab.

How would a script affect an internal function like that, all I am doing is Player:LoadCharacter(), and when I test using local server the function finishes in 5secs or so.
image

Is the SpawnLocations RespawnTime set to 10+ seconds?

Also, (as someone else said), use coroutines. Here’s an example:

game:GetService("Players").PlayerAdded:Connect(function(Player)
    coroutine.resume(coroutine.create(function()
        Player:LoadCharacter()
    end))
end)

I’d also recommend turning off CharacterAutoLoads (found under the Players service).

It’s set to 0, but that doesnt matter when CharacterAutoLoads is off

Doesn’t help

It has to be off if you want to use LoadCharacter or else you are loading your character twice

Did you even test it? A coroutine creates a new thread, so anything yielding it would not affect whatever’s in the coroutine.

As far as CharacterAutoLoads; I just told you that so you’d know if this would work or not. (Without yielding the code, because that’s the main problem.)

Yes I did test, LoadCharacter is the yielding function, it doesnt help executing it in a new thread.
As in:

	local lc = os.clock()
	player:LoadCharacter() -- Wrap it or not, same result
	print(os.clock() - lc) -- Prints ~14

I copy pasted everything to a newly created place with LoadCharacter working properly, and now it works, the previous place is cursed or something??

Apparently it’s my sounds, I have a couple of footstep sounds in SoundService and they are causing the :LoadCharacter to take longer to finish.