Player:LoadCharacter() causes server to completely Freeze for a few seconds

Hello everyone,

I’ve come with a rather complex issue, and I’m still unsure if it has anything to do with code base or not, but I’ll explain the situation.

An FPS game that I’ve been working on for a couple years at this point started having issues a bit ago, that I thought I’d revisit. The primary issue I’m having is below:

  • Whenever a Players Character is being loaded into my game, the server seemingly freezes (all Player replication, translations of Parts/Models suffer from said freeze).

It takes about ~3.5 seconds to stop spiking the server. I should also note that the Player who was being spawned in suffers a complete FPS drop on their client as well when loading in, which also resolves after about ~3.5 seconds.

All my friends have reported the ping spiking up to as high as 300ms whenever it starts to settle and the game becomes responsive, so it seems the results are relatively consistent for everyone. My friend group is pretty spread out.

Here is a video that accurately displays what happens whenever ANYONE spawns into the Test Place experience (Place file used for testing features before they’re pushed to the main game).


So, that’s the problem. This issue only started occurring in my Test Place of my game, and the current version doesn’t seem to be affected by this problem at all. The server doesn’t suffer any spikes and the spawning Player also does not experience FPS drops to flat 0, whatsoever.

I’ve constantly compared my code base (especially the round spawning functions) to the older version of the game, and could not find any significant changes other than a few new added spacing between lines. The code has been untouched since the last version, but for whatever reason the Test Place suffers from this problem.


This issue seems to be fully reproducible on both Roblox Studio, as well as Roblox Player. Upon checking the Task Scheduler within Roblox Studio, whenever the issue occurs, everything goes down to 0% activity with the rate taking a huge dip in performance too. This completely locks up Studio for those roughly ~3.5 seconds.

I’m not performing any crazy changes to the Character, or running several loops or adding tons of content whenever the Player spawns. All it’s really doing is adding Body Colors + Accessories to the base R6 rig on Spawn, which shouldn’t cause EVERYTHING to basically stop working for a few seconds.

The issue only ever occurs when calling game.Players.Vyntrick:LoadCharacter(), so it has to be something related to this function, and I’m stumped for ideas. I’ve tried reprogramming things, switching to module scripts, checking for yielding, etc. just to be met with no resolution.

Any ideas on what I could do to get myself out of this mess?


P.S, you can try testing this yourself by comparing the Main place file to the Test one.

[OA] Claw In The Chamber - Roblox
[CITC]: Public Test Branch - Roblox

Update!

So apparently, when attempting to construct a local repro file for others to test the issue, I ended up finding the source of the lag. It was coming from the Main Menu ScreenGui that is present in the showcase video of the problem. I’m currently investigating to see what I can remove or redo to mitigate this lag. Keep in mind that no scripts were running at the time of testing, and it appears scripts have absolutely nothing to do with this issue at all.

I’ll mark this as a solution when I end up finding a resolution to the problem.

7 Likes

I’m heading to sleep (as it is VERY late, and been up trying to solve this issue). I’ll be a bit delayed if anyone happens to reply, but I appreciate any possible direction I could go to resolve said issue.

3 Likes

I’m awake now, so any help would be genuinely appreciated.

2 Likes

This is sadly still a problem, and by the looks of it, no one knows what it could be.

1 Like

Hello fellow friend!

Could you possibly provide some script to give better context? How is the :LoadCharacter() being done? May you try using command just for the purpose of :LoadCharacter() when spawned in to see if that the issue?

Let me know how it went!

2 Likes

Well, from the testing I performed before creating this post, it seems something as simple as calling :LoadCharacter() from the command line causes this lag.

Here is how I’m handling Player spawns:

  • Player Joins Game
  • Server detects they enter the menu, loading their Inventory instead of Character
  • When the Player hits “Play Game” it tells the server to spawn using the in-game mode, resulting in their inventory not being loaded, but only their Character to save on Server Performance.

Even disabling this script and custom spawn systems I created and just calling :LoadCharacter causes this lag, so I do not believe sending a script would be necessary, considering some of the code is as basic as adding accessories to the character, and changing body colors after they get spawned.

I suppose this is more a bug report than it is a scripting support post, but as it seems there is literally no reliable way to bug report this, I’m hoping someone with access sees this issue. I’m just hoping someone might have an idea of some sort of niche scripting practice that can cause this issue.


If it helps, I also tried a completely different game with barely any content, and calling :LoadCharacter() also causes slight lag when the Player spawns. It seems that the problem scales with the size of the game, regardless of how much performance heavy your scripts are.

1 Like

Have you played the game without being in roblox studio? I just tested it, and it doesn’t seem to be an issue, that why I asked to provide the script. It could just be weak hardware. Maybe try joining your game without being in studio if you haven’t and let me know how it goes!

2 Likes

I already tried this initially. Sadly, the problem still occurred. However, what’s really strange is that other devs Experiences with custom spawning systems don’t seem to trigger this issue for me, as well as another experience I work on here that does force :LoadCharacter() spawning:

For whatever reason, experiences I created have this really terrible lag that I cannot seem to resolve. Even when all my plugins are completely disabled. I only use trusted plugins that I have read up and seen tested by others, so it cannot possibly have been that.

1 Like

Have you had more people testing it? Be helpful if there’s more data. I tested both games and I didn’t feel “lag” it just maybe took around 1 second to load in after pressing play. From the video, it doesn’t seem like you have a powerful pc seeing as 40-50 FPS. I get 100+ FPS so it not an issue for me, so I don’t know how to duplicate your problem. Potential cause can also be driver, so maybe look into that!

2 Likes

My studio has been experiencing weird fluctuation issues but others in my friend group who actively help me test the experience say they also experience a really bad ping spike everytime someone respawns. This isn’t the first time :LoadCharacter() has caused issues like this. Also, my computer has been able to handle studio for years without any issues. I’ve considered a reinstall of my computer to fix said issue, but that shouldn’t be affecting my entire game as well as people playing it. That’s why I’m concerned.

I do see how my own performance would affect loading, however it shouldn’t be affecting others. I really appreciate the input though. Glad someone has responded :sweat_smile:

Of course, it seemed like you were on a lonely island lol.

By the way, have you also tried disabling beta features? Sometimes roblox can be a little funny from time to time, you could reach out to support to verify or report it if it potential bug on certain hardware or something. It weird that you and your friend group having this issue as I never had any issue with :LoadCharacter() and when I test your game. So yeah, that all I know. Interesting concept game!

I was gonna a clip of me playing the game but my recorder is recording at 0 FPS for some reason. :sob:

1 Like

It’s alright, and I appreciate the help. I double checked the beta features, and I’ll also try to disable them all, but I’m unsure if this will solve anything. I could of sworn I tried it already, but I’ll do a once over.

I agree, it’s weird it’s happening to them too. One of my friends they couldn’t observe a spike while others said they were. When there is 4-5 people in one game trying to play competitively, it really ruins the fluidity of combat, and I’d love to get this resolved soon.

edit: it didn’t change anything at all, sadly.

2 Likes

I could be wrong, but it doesn’t sound at all like :LoadCharacter is the cause of this in itself, but rather whatever your scripts are doing upon player spawning, player.CharacterAdded

1 Like

LoadCharacter has its problems and issues. I used to use LoadCharacter in Bloxy Kart v3.5 and older, and this exact issue occurs only sometimes. Probably an engine issue more than an issue in your code, because after a while, it fixes itself.

What we did was avoid it all together by using alternatives. We didn’t actually need LoadCharacter(), so we got rid of it and instantly set the players character with a default model if needed.

If possible, I would try temporarily setting the player’s respawn time to 0 temporarily, then Player.Character.Humanoid.Health = 0, then setting the respawn time back.

How to fix for your experience.

Step 1: Add a RemoteEvent in ReplicatedStorage called “OnLoadForClient”
Step 2: Add a RemoteFunction in ReplicatedStorage called “QuickRespawn”
Step 3: Add this function and code to the place where you would like to call Player:LoadCharacter()

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local quickRespawn = ReplicatedStorage.QuickRespawn
local onLoadForClient = ReplicatedStorage.OnLoadForClient

function loadCharacter(Player: Player)
	task.spawn(function() -- We need this so we do not cause any infinite loads if the player leaves while we are loading the character. Removing it will cause issues if the player leaves when this function is called.
		local character = Player.Character or Player.CharacterAdded:Wait()
		local humanoid: Humanoid = character.Humanoid

		quickRespawn:InvokeClient(Player) -- This script is designed to Invoke the client safely. Do not invoke the client unless you absolutely know how to script it safely.

		humanoid.Health = 0
		
		onLoadForClient:FireClient(Player) -- Tells the client to fix the respawn time so you do not have instant respawns.
	end)
end

Step 4: Add this code in a LocalScript to StarterPlayer.StarterPlayerScripts:

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

local quickRespawn = ReplicatedStorage.QuickRespawn
local onLoadForClient = ReplicatedStorage.OnLoadForClient

local defaultRespawnTime = Players.RespawnTime

quickRespawn.OnClientInvoke = function()
	Players.RespawnTime = 0
	
	return -- Tells the server that it is ready to kill
end

onLoadForClient.OnClientEvent:Connect(function()
	Players.RespawnTime = defaultRespawnTime
end)

Step 5:
Substitute Player:LoadCharacter() for loadCharacter(Player)

1 Like

I am not yielding the CharacterAdded event or doing anything complex. All I’m doing is copying accessories based off the equipped character skin. Also, even if this were the case, why does it make the entire server plummet in terms of performance? (e.g: The entire task scheduler in Studio completely grinds to a halt).

Is there some way that I could be achieving that terrible of performance?

1 Like

I’m going to test this issue on my own. If I can reproduce, I’ll make a bug report.

I’ve tested the issue and I can’t seem to reproduce on a blank baseplate. It’s likely due to the fact that you have some unoptimized code which are connected to CharacterAdded functions. Let me give this thread a look one more time and I’ll see if there’s enough information for me to provide any advice.

Edit #2: Okay, here are your options. You can make a bug report, even if it’s in your specific place, and have Roblox staff look into it. However, before you do that, can you send any script that handles a character-added event? If you want to talk on Discord, it’s the same as my roblox username, if that makes you more comfortable. If you still can’t seem to resolve the issue, then you can make a bug report, and give roblox staff a reprod file, though it may take a while for a staff member to get to it.

1 Like

Not sure if this helps, but as I said before, new games don’t seem to be heavily impacted as the performance seems to scale with the size of the game. This bug was actually a thing in 2016 initially, and Roblox claims to have fixed it. The guy in that post appears to be experiencing the exact same issue I am in the present day.

Also keep in mind that someone else has posted a similar problem whenever someone respawns at the very bottom of the thread, just recently too.

LoadCharacter in the past used to instantly respawn the character with very little delay, but you can notice a small skip in the time it takes for the Character to at least load.

That gives me an idea then:

Can you run a MicroProfiler benchmark just for the Player:LoadCharacter() call itself and nothing else?

Literally just wrap your function in debug.profilebegin("LoadCharacter") and debug.profileend() and record the microprofiler. Let me know your results and hopefully we can go from there considering you can only repro from your place file.

This’ll mainly just tell us whether it’s the LoadCharacter call itself or your other scripts that are causing issues.

1 Like

If I were you, I’d first verify that :LoadCharacter() is actually causing the lag. I assume you did this already, but wherever you are calling :LoadCharacter(), remove all of the code surrounding it. If it doesn’t lag anymore, narrow the script down until you find the problem.

If removing all the surrounding code doesn’t work, I’d then try to disable all other scripts in the game. There could be a .CharacterAdded function someone that could be causing the lag. It could also be a .ChildAdded or .DescendantAdded function (I’d use Ctrl + Shift + F to search for these functions).

It could also be an issue with mass part replication, or parts falling into the void. I’d check that out too. How many scripts do you have inside StarterCharacter? Also, do you have CharacterAutoLoads disabled?

I can almost guarantee you this problem is a result of the code and/or parts in your game (since you are revisiting this problem), so I would just keep that in mind.

1 Like

Hey um, I suppose this says a lot? I just wrapped the :LoadCharacter() call using the two debug methods you provided, and this is the result:

Also, is this what you mean by record?

Also it appears right after the LoadCharacter call, this also piles up for a long time it seems. I have no clue what it could mean though.