Tool is being cloned into backpack twice?

So far, all of this script works perfectly apart from the fact that when I try to clone the tool at the end, it does it twice. I’ve checked and there is no other script interfering or anything that is causing two of them to enter the player’s backpack. I just want it to be one that is cloned. I’m honestly baffled with what I’ve done wrong, and I guarantee it’ll be something with an easy fix that I just haven’t noticed.

local GroupId = 10068814 --Replace 1234567 with your group ID

local RanksAndUniforms = {
	
	
	{1, "http://www.roblox.com/asset/?id=1375365975", "http://www.roblox.com/asset/?id=1375387127", "ConfederateVolunteer", -- Volunteer
		"ConfederateInfantryBackpack", "Pattern 1853 Enfield", "", "", ""},
	
	{2, "http://www.roblox.com/asset/?id=1429220245", "http://www.roblox.com/asset/?id=1429225492", "1stConfederateInfantry", -- Private
		"ConfederateInfantryBackpack", "Pattern 1853 Enfield", "", "", ""},
	
	{255, "http://www.roblox.com/asset/?id=1429214494", "http://www.roblox.com/asset/?id=1429223605", "ConfederateGeneral", -- General
		"ConfederateOtherBackpack", "Colt Army M1860", "Sabre", "Compass", "Spyglass",}
	
	
}

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		wait()
		for i = 1, #RanksAndUniforms do
			local RankAndUniform = RanksAndUniforms[i]
			
			local RequiredRank = RankAndUniform[1]
			
			local ShirtTemplate = RankAndUniform[2]
			local PantsTemplate = RankAndUniform[3]
			
			local Hat = RankAndUniform[4]
			local Backpack = RankAndUniform[5]
			
			local Weapon1 = RankAndUniform[6]
			local Weapon2 = RankAndUniform[7]
			local Tool1 = RankAndUniform[8]
			local Tool2 = RankAndUniform[9]
			
			if Player:GetRankInGroup(GroupId) == RequiredRank then
				Character:WaitForChild("Shirt").ShirtTemplate = ShirtTemplate
				Character:WaitForChild("Pants").PantsTemplate = PantsTemplate
				
				local WearHat = game.ServerStorage.Hats:FindFirstChild(Hat)
				local WearBackpack = game.ServerStorage.Backpacks:FindFirstChild(Backpack)
				
				local EquipWeapon1 = game.ServerStorage:FindFirstChild(Weapon1)
				local EquipWeapon2 = game.ServerStorage:FindFirstChild(Weapon2)
				local EquipTool1 = game.ServerStorage:FindFirstChild(Tool1)
				local EquipTool2 = game.ServerStorage:FindFirstChild(Tool2)
				
				wait(0.4)
				Character.Humanoid:AddAccessory(WearHat:Clone())
				Character.Humanoid:AddAccessory(WearBackpack:Clone())
				
				EquipWeapon1:Clone().Parent = Player.Backpack
			end
		end
	end)
end)

Upon checking the code around, I can’t spot out the issue on this code by its own. It must be an external factor, unless somehow CharacterAdded was fired twice. Could you add a printing function after the CharacterAdded event?

Looks like you’re onto something :thinking:

Ah yes, somewhere in the game, the LoadCharacter function was fired most likely. Does your game have any custom respawning logic or no?

Yes it does now that I remember. But wouldn’t the tools be removed from the player’s backpack once they respawned?

Not quite, if they were rapidly respawned between with a deferred timing, the wait() allowed them to be spawned with duplicates.

So what should I do to fix them?

I think that wait() is unnecessary, you can try removing that, but if there was different issues without wait(), you should try yielding for something than using wait().

Alternatively, more or less a band-aid solution, you can check whether the user has a duplicate item in their backpack and don’t add a new one.

I found an easy fix. It was just to kill the player instead of respawning them. That way they lose their tools.