Calling LoadCharacter multiple times causes the character to load with duplicates of their accessories. It can also cause character scripts to run multiple times. I believe this can also happen when you have CharacterAutoLoads on and a call to LoadCharacter happens at the same time the character auto loads.
It seems like this bug has been around for a while:
I know I can easily make sure my scripts don’t call LoadCharacter multiple times in the same frame and I can turn off CharacterAutoLoads. However, if someone doesn’t know why this issue is happening (and it is executing character scripts multiple times each time their character respawns) it can cost a bit of time to discover the issue. So at the very least it would be nice if this issue was documented on the developer hub on the Player/LoadCharacter page.
this is a known issue. calling LoadCharacter() when you’ve already called it and it hasn’t finished will cause issues. Are you able to wait for the character loading finished event before calling again?
As I said, it’s fairly simple to work around the issue. The problem is that much like bedbugs, the bite can hurt and the bug can be hard to find.
If it’s a known issue to the staff, it would be great if it could be made widely known to the game developers. Something like a warning when you try to load a character that is already in the process of loading (if possible) or a note on the developer hub page for LoadCharacter.
Apologies for posting in the wrong place, I don’t have permissions to start a new issue.
I’ve face an issue with calling LoadCharacter() causing threads to block.
It’s a real edge case, if I call it just as a player is leaving it blocks indefinitely.
To give a some context to this:
I have a minigames compilation, Island Minigames.
Each minigame starts by calling a shared module to:
Set the players spawn location to a spawn pad in the minigame
Calls player:LoadCharacter() to teleport them (this also has the benefit of giving them a “fresh” player i.e. full health etc)
Here’s (a simplified) version the code I’m calling:
for _,player in pairs(game.Players:GetPlayers()) do
player.RespawnLocation = spawnObj
print(os.date("%X").." load char for "..player.Name)
player:LoadCharacter()
print(os.date("%X").." load char done")
And here’s an example of what I see in the console when it gets stuck:
16:34:43 load char for player1
16:34:43 A player has left: player1
16:35:33 The player player2 joined to game
Notice it never progresses beyond the loadcharacter.
There’s no errors or warnings, I’ve found instances of my game that have been stuck in this state for over 20 minutes so it doesn’t timeout either.
Is this a bug or developer error?
Hi, Thanks for responding. Very difficult to repro.
Like I say it only happens when calling LoadPlayer() on a player object just as they are leaving the game.
I’d need to find a volunteer who was prepared to keep joining and quitting to repro the issue
I’ve entered a ticket into our system, and I will try to repro and fix this issue. In the meantime, you might be able to solve your problems, by explicitly setting the Character’s position and the Humanoid’s health instead of calling Player:LoadCharacter. You could also try calling the contents of the for loop in you code sample inside a spawn function, which would mean the for loop would continue even if the call to Player:LoadCharacter() doesn’t return