Character scripts loading duplicates when LoadCharacter is called

When LoadCharacter is called, the character spawns in with at least 2 extra instances of body colors, shirt, pants and each of the character scripts.

The shirts and pants also seem to not do their function in this situation - I didn’t have time to check the asset IDs, so I can’t be specific on that one sorry!

Screenshot_596

It only seems to happen when called in response to a touch - all other times I have called the LoadCharacter method have worked normally.

To reproduce:

  • Go into studio

  • Make a new part and put a script in it

  • Give the script the following code:

    script.Parent.Touched:Connect(function(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
    if Player then
    Player:LoadCharacter()
    end
    end)

  • Test with play solo and touch the part, then check the contents of the loaded character

I have no idea how long it has been around - I only experienced it an hour or two before this post - although would it be safe to assume it came with the new studio update?

This bug is because you’re calling LoadCharacter multiple times in a single step. It doesn’t have anything to do with touch, that’s just one of many cases that can cause LoadCharacter to fire multiple times in a step.

This code will also reproduce the issue:

for i = 1, 10 do 
  spawn(function() -- necessary to prevent yielding
    game.Players:GetChildren()[1]:LoadCharacter() 
  end) 
end

The temporary fix (although even if this bug didn’t exist, you should be checking this anyways) is to not spam LoadCharacter.

Edit: Also, this is not a studio bug since it happens both in studio & in-game. Studio bugs are for bugs that only happen in studio. I’ve moved it to the correct category.

4 Likes

Alright, thanks. I didn’t even consider that lol

Use GetPlayers smh

3 Likes