Attachs are not loading into character

  1. What do you want to achieve? Keep it simple and clear!
    I want to attach meshparts into character with Motor6D

  2. What is the issue? Include screenshots / videos if possible!
    For some players, the clones are not applied, it happens very occasionally. However, if the player resets, the attachments are equipped correctly

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    For a moment I thought this was because the player’s character wouldn’t finish loading, I tried adding some checks and waits but it didn’t work. I would like this to work on the player’s first spawn (when the player just spawns) but it has to reset multiple times for it to work properly.

This is my code

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")

local CustomItems = ReplicatedStorage:WaitForChild("CustomItems")
local Flashlights = CustomItems:WaitForChild("Flashlights")
local Hammers = CustomItems:WaitForChild("Hammers")
local Masks = CustomItems:WaitForChild("Masks")
local Vests = CustomItems:WaitForChild("Vests")

local function equipItemsForCharacter(character)
	wait(0.145)
	if character.Name == "ragdoll" then
		return
	end

	local player = Players:GetPlayerFromCharacter(character)
	if not player then
		return
	end
	
	local requiredParts = {"LowerTorso", "RightUpperLeg", "LeftHand", "Head", "UpperTorso"}
	for _, partName in ipairs(requiredParts) do
		while not character:FindFirstChild(partName) do
			character:WaitForChild(partName)
			wait()
		end
	end

	local function FlashlightHandler(Name)
		
		local NewFlashlight = Flashlights:WaitForChild(Name):FindFirstChild("Handle"):Clone()
		local NewFlashlightHip = Flashlights:WaitForChild(Name):FindFirstChild("FlashLightHip"):Clone()
		
		wait()
		
		NewFlashlightHip.Parent = character:WaitForChild("LowerTorso")
		NewFlashlightHip:WaitForChild("Welder"):FindFirstChild("Motor6D").Part0 = character:WaitForChild("LowerTorso")
		NewFlashlight.Parent = player.Backpack:WaitForChild("Flashlight")
		
		if character:WaitForChild("LowerTorso"):FindFirstChild("FlashLightHip") then
			warn("FlashlightHip Loaded for "..player.Name)
		else
			warn("FlashlightHip NOT loaded for "..player.Name)
		end
	end

	local function HammerHandler(Name)
		local NewHammer = Hammers:WaitForChild(Name):FindFirstChild("Hammer"):Clone()
		local NewHammerHip = Hammers:WaitForChild(Name):FindFirstChild("HammerHip"):Clone()
		
		wait()
		
		NewHammer.Transparency = 1
		for _, decal in ipairs(NewHammer:GetChildren()) do
			if decal:IsA("Decal") then
				decal.Transparency = 1
			end
		end
		
		NewHammerHip.Parent = character:WaitForChild("RightUpperLeg")
		NewHammerHip:WaitForChild("Welder"):FindFirstChild("Motor6D").Part0 = character:WaitForChild("RightUpperLeg")
		NewHammer.Parent = character:WaitForChild("LeftHand")
		NewHammer:WaitForChild("Welder"):FindFirstChild("Motor6D").Part0 = character:WaitForChild("LeftHand")
		
		if character:WaitForChild("RightUpperLeg"):FindFirstChild("HammerHip") then
			warn("HammerHip Loaded for "..player.Name)
		else
			warn("HammerHip NOT loaded for "..player.Name)
		end
	end

	local function MaskHandler(Name)
		local NewMask = Masks:WaitForChild(Name):FindFirstChild("MaskTemplater"):Clone()

		NewMask.Transparency = 1

		for _, decal in ipairs(NewMask:GetChildren()) do
			if decal:IsA("Decal") then
				decal.Transparency = 1
			end
		end

		NewMask.Filter.Transparency = 1
		for _, decal in ipairs(NewMask.Filter:GetChildren()) do
			if decal:IsA("Decal") then
				decal.Transparency = 1
			end
		end

		NewMask.Glass.Transparency = 1
		for _, decal in ipairs(NewMask.Glass:GetChildren()) do
			if decal:IsA("Decal") then
				decal.Transparency = 1
			end
		end

		NewMask.Parent = character:WaitForChild("Head")
		NewMask:WaitForChild("Welder"):FindFirstChild("Motor6D").Part0 = character:WaitForChild("Head")
	end

	local function VestHandler(Name)
		local NewVest = Vests:WaitForChild(Name):FindFirstChild("VestTemplater"):Clone()

		NewVest.Transparency = 1

		for _, decal in ipairs(NewVest:GetChildren()) do
			if decal:IsA("Decal") then
				decal.Transparency = 1
			end
		end

		NewVest.Parent = character:WaitForChild("UpperTorso")
		NewVest:WaitForChild("Welder"):FindFirstChild("Motor6D").Part0 = character:WaitForChild("UpperTorso")
	end

	-- Flashlights
	local flashlightEquipped = player:WaitForChild("PlayerInfo"):WaitForChild("EquippedFlashlight").Value
	if flashlightEquipped == "Basic" then
		FlashlightHandler("Basic")
	elseif flashlightEquipped == "Bloody" then
		FlashlightHandler("Bloody")
	elseif flashlightEquipped == "Golden" then
		FlashlightHandler("Golden")
	elseif flashlightEquipped == "Wooden" then
		FlashlightHandler("Wooden")
	elseif flashlightEquipped == "Metal" then
		FlashlightHandler("Metal")
	elseif flashlightEquipped == "Crystal" then
		FlashlightHandler("Crystal")
	elseif flashlightEquipped == "Dismantled" then
		FlashlightHandler("Dismantled")
	elseif flashlightEquipped == "Volcanic" then
		FlashlightHandler("Volcanic")
	elseif flashlightEquipped == "Rustic" then
		FlashlightHandler("Rustic")
	elseif flashlightEquipped == "Ancient" then
		FlashlightHandler("Ancient")
	elseif flashlightEquipped == "Radioactive" then
		FlashlightHandler("Radioactive")
	end

	-- Hammers
	local hammerEquipped = player:WaitForChild("PlayerInfo"):WaitForChild("EquippedHammer").Value
	if hammerEquipped == "Basic" then
		HammerHandler("Basic")
	elseif hammerEquipped == "Bloody" then
		HammerHandler("Bloody")
	elseif hammerEquipped == "Golden" then
		HammerHandler("Golden")
	elseif hammerEquipped == "Wooden" then
		HammerHandler("Wooden")
	elseif hammerEquipped == "Metal" then
		HammerHandler("Metal")
	elseif hammerEquipped == "Crystal" then
		HammerHandler("Crystal")
	elseif hammerEquipped == "Lion" then
		HammerHandler("Lion")
	elseif hammerEquipped == "Liminal" then
		HammerHandler("Liminal")
	elseif hammerEquipped == "Ban" then
		HammerHandler("Ban")
	elseif hammerEquipped == "Dismantled" then
		HammerHandler("Dismantled")
	elseif hammerEquipped == "Ancient" then
		HammerHandler("Ancient")
	elseif hammerEquipped == "Radioactive" then
		HammerHandler("Radioactive")
	elseif hammerEquipped == "Volcanic" then
		HammerHandler("Volcanic")
	end

	-- Masks
	local maskEquipped = player:WaitForChild("PlayerInfo"):WaitForChild("EquippedMask").Value
	if maskEquipped == "Basic" then
		MaskHandler("Basic")
	elseif maskEquipped == "Bloody" then
		MaskHandler("Bloody")
	elseif maskEquipped == "Golden" then
		MaskHandler("Golden")
	elseif maskEquipped == "Wooden" then
		MaskHandler("Wooden")
	elseif maskEquipped == "Metal" then
		MaskHandler("Metal")
	elseif maskEquipped == "Crystal" then
		MaskHandler("Crystal")
	elseif maskEquipped == "Dismantled" then
		MaskHandler("Dismantled")
	end

	-- Vests
	local vestEquipped = player:WaitForChild("PlayerInfo"):WaitForChild("EquippedVest").Value
	if vestEquipped == "Basic" then
		VestHandler("Basic")
	elseif vestEquipped == "Bloody" then
		VestHandler("Bloody")
	elseif vestEquipped == "Golden" then
		VestHandler("Golden")
	elseif vestEquipped == "Wooden" then
		VestHandler("Wooden")
	elseif vestEquipped == "Metal" then
		VestHandler("Metal")
	elseif vestEquipped == "Crystal" then
		VestHandler("Crystal")
	end
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		equipItemsForCharacter(character)
	end)
end)

Can someone help me please? :smiling_face_with_tear: