How do I prevent accessories from cloning when using :LoadCharacter()?

I have :LoadCharacter() on a button so when the player clicks on a button it will load their saved outfit. The problem is that every time I press it a second time it duplicates the accessories in the character and so on. I want to know how to prevent this. I tried adding a debounce to the :LoadCharacter, but I still got the same result. I also tried using player.CharacterAppearanceLoaded:wait() and it prevented the character’s appearance from loading.

I’ve seen other people have the same problem on the dev forum.

or

Is this a bug and how do I prevent this?

1 Like

I just wrapped calls to LoadCharacter in a separate function that tests to see if it’s already been called before calling it. So essentially a debounce for LoadCharacter. Then I only use that function and don’t call LoadCharacter directly. This method may still cause problems if you have CharacterAutoLoads on.

Although if you’re just changing character appearance, you may be able to cut out LoadCharacter altogether and just use HumanoidDescription.

2 Likes

I think I’ll still use LoadCharacter since HumanoidDescription doesn’t work with custom accessories. :+1:

1 Like

This is what I used as my ‘debounce’

local function test(player)
	functionRunning = true
	print("loading character")
	player:LoadCharacter()
	
	wait(6)
	functionRunning = false
end

I seem to get the same results even though I have set CharacterAutoLoads equal to false in the script.

That snippet only sets the functionRunning variable, but it doesn’t use it. Also, you don’t need the wait since LoadCharacter yields.

Try this:

local function test(player)
    if functionRunning then return end
    functionRunning = true
    print("loading character")
    player:LoadCharacter()
    functionRunning = false
end
2 Likes