CharacterAppearanceLoaded fires twice when the player joins the game

I haven’t been able to figure out why this happens, nor how to fix it:
I am calling a CharacterAppearanceLoaded function from the PlayerAdded event, however, when i first join the game for some reason it fires twice so the function that is called by CharacterAppearanceLoaded runs twice, this is an inconvenience for me since it’s giving the player tools twice.

Code:

function onPlayerAdded(Player)
---[not relevant code]
	Player.CharacterAppearanceLoaded:Connect(CharLoaded)		
end

function CharLoaded(char)
---[not relevant code]
end

Players.PlayerAdded:Connect(onPlayerAdded)

The problem doesnt fall in anything related to the parts of code im not showing btw, please help, i’ve been stuck in here for too long, i have tried putting debounces but nothing works :frowning:

The example script you provided is only executing once for me, is it possible you have multiple copies of the same script? What’s more likely is that you have 2 scripts which are copying tools into the player’s backpack upon their character respawning/reloading.

local Players = game:GetService("Players")

function onPlayerAdded(Player)
	---[not relevant code]
	Player.CharacterAppearanceLoaded:Connect(CharLoaded)		
end

function CharLoaded(char)
	print("123")
	---[not relevant code]
end

Players.PlayerAdded:Connect(onPlayerAdded)

Run this in an empty environment and 123 will only be printed once each time the CharacterAppearanceLoaded event fires.

1 Like

I put the exact code you sent there to test and it still fires twice, as you can see on the console, and no, i dont have other repeated scripts that do this, the script is in ServerScriptService

RobloxScreenShot20211207_104638097

By empty environment I was referring to any one of the various available templates.

local Players = game:GetService("Players")

local function CharLoaded(char)
	---[not relevant code]
end

local function onPlayerAdded(Player)
	---[not relevant code]
	Player.CharacterAppearanceLoaded:Connect(CharLoaded)
end

Players.PlayerAdded:Connect(onPlayerAdded)

I’m not sure if this will change anything but it’s usually a good idea to have functions defined in the script before you specify that they should be connected to an event.

I just tested it in an empty game and it seems to only fire once now, then it must be something that is in the other game that makes it fire twice but i dont have any ideas on how to find out what causes it. Btw putting the function before the PlayerAdded function also didnt do anything.

Quick update: I have been testing the game and it seems like the problems only happens in studio play test, tho im still a bit skeptical about it. I will check out if i found the source of the problem and update you, thanks for the help tho!