-- Don't touch anything below this point unless you know what you're doing!

local DefaultRig = Rigs[0]

local function Update(Character)
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	if not Humanoid or Humanoid.Health <= 0 or Humanoid.RigType ~= Enum.HumanoidRigType.R15 then return end
	Humanoid:UnequipTools()
	
	local ConvertTo = Rigs[RigVersion]
	
	if IgnoreBodyParts then
		for _, Part in pairs(ConvertTo:GetDescendants()) do
			if Character:FindFirstChild(Part.Name) and Part:IsA("BasePart") then
				Humanoid:ReplaceBodyPartR15(Part.Name, Part:Clone())
			end
		end
	else
		for _, Part in pairs(Character:GetChildren()) do
			if Part:IsA("MeshPart") then
				local EquivalentDefault = DefaultRig:FindFirstChild(Part.Name)
				local EquivalentSkinned = ConvertTo:FindFirstChild(Part.Name)
				if EquivalentDefault and EquivalentSkinned and EquivalentDefault.MeshId == Part.MeshId then
					Humanoid:ReplaceBodyPartR15(Part.Name, EquivalentSkinned:Clone())
				end
			end
		end
	end
end

local function PlayerJoined(Player)
	Player.CharacterAppearanceLoaded:Connect(Update)
end


game:GetService("Players").PlayerAdded:Connect(PlayerJoined)
