MorphService
Last year I created a MorphService, but it could be better, so I made better.
The service works by taking a module containing models named as body part limbs (e.g. “Torso”, “Left Arm”, “Lower Right Arm”) and welding parts you put inside the limb model to a character.
In this new version, I lean more on OOP coding styles and apply things I’ve learnt since I made the first one.
How to use the module
Inside the MorphHandler script, simply initialise it as such
local morphService, decorators = require("path to the module")()
The main module returns a tuple containing the service and decorator modules.
Full code example
-- Server script example
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlayerService = game:GetService("Players")
local assets = ReplicatedStorage.Assets
local modules = ReplicatedStorage.Modules
local morphs = assets.Morphs
local backpackMorph = morphs.Backpack
-- initialise the MorphService
local morphService, decorators = require(modules.MorphService)()
-- initialise the morph
local myMorph = morphService.new({
morph = backpackMorph,
morphType = "Accessory"
})
PlayerService.PlayerAdded:Connect(function(player)
-- wait for the normal avatar to load fully before applying
player.CharacterAppearanceLoaded:Connect(function(character)
-- apply the morph
myMorph:applyMorph({
character = character,
decorators = {
decorators.removeAccessories
},
config = {
overwriteExistingMorphs = true,
cloneMorphChildren = false
}
})
end)
end)
Resulting morph applied to my character
How the module works
The main module returns a function which itself returns a tuple of MorphService, Decorators.
MorphService corresponds with the Service module.
Decorators corresponds with the Decorators module.
Service contains the .new function for initialising a new morph that can be applied to a character.
This the only place where OOP is included.
The Morph type contains a function called applyMorph which can be called after creating a new Morph.
Supporting modules Types and Utility contain all the types that are used and helper functions.
The Decorators module contains the available decorators to do operations on the character to do something specific like removing clothing, accessories and packages. These decorators can be applied based on what your morph needs.
decorators supports any function with the type (character: Model) -> nil.
Morphs can easily be created by copying the given MorphTemplate inside ReplicatedStorage/Assets/Morphs and deleting the limbs you won’t use.
The Reference part within the limb is your guide for where things are positioned on the character. Simply place what you want inside the limb model and place it based on the Reference part.
Once you have made your morph apply it to characters with a script.
See ‘How to use the module’ for using the module in a script.
Resource
MorphService.rbxl (84.5 KB)
All scripts contain documentation





