Hello, i’ve been working on a game that has an outfit system that uses a template character (stored in serverstorage, it’s the r15 template from Moon Animator) for the ouftits, and then applies an humanoid description to give the character clothes. The problem here is that the player when dies, the parts get frozen like one second after it dies. Here’s a video in what happens:
Here’s the code that applies the outfit to a character
function MorphService:MorphInto(Player, TeamName, MorphName)
return Promise.new(function(resolve)
local BaseMorph: Model = Morphs:FindFirstChild(TeamName) and Morphs[TeamName]:FindFirstChild(MorphName)
if not BaseMorph then warn(string.format("[WARNING] No Morph found with the name %s", MorphName)) resolve() return end
local MorphContainer = Instance.new("Folder")
local Char = TemplateCharacter:Clone()
-- Sets up character scripts
for _, script in pairs(game.StarterPlayer.StarterCharacterScripts:GetChildren()) do
local newScript = script:Clone()
newScript.Parent = Char
newScript.Enabled = false
Promise.delay(0):andThen(function()
newScript.Enabled = true
end)
end
MorphContainer.Parent = Char
MorphContainer.Name = "Morph"
local NewMorph = BaseMorph:Clone()
-- Applies humanoid description
if NewMorph:FindFirstChild("HumanoidDescription") then
local HumDescription = NewMorph.HumanoidDescription
HumDescription.Parent = Char
WaitUntilValidHumanoid(Char)
:andThenCall(Char.Humanoid.ApplyDescription, Char.Humanoid, HumDescription) -- Applies humanoid description
:andThenCall(GetPlayerHumanoidDescription, Player) -- Gets the Player's humanoid description
:andThen(function(PlayerHumDescription)
if not PlayerHumDescription then return end
-- Default the colors to the player's
for DescColorPartName, PartsTable in pairs(HumanoidDescriptionColorsToParts) do
if HumDescription[DescColorPartName] == Color3.fromRGB(0, 0, 0) then
for _, PartName in pairs(PartsTable) do
Char[PartName].Color = PlayerHumDescription[DescColorPartName]
end
end
end
if HumDescription.Face == 0 and PlayerHumDescription.Face ~= 0 then
GetFaceTexture(PlayerHumDescription.Face):andThen(function(PlayerFaceTexture)
Char.Head.face.Texture = PlayerFaceTexture
end)
end
end)
end
-- Applies morph parts to the character
for _, v in pairs(NewMorph:GetDescendants()) do
if v:IsA("BasePart") then
v.Anchored = false
v.CanCollide = false
v.CanQuery = false
v.CastShadow = false
v.Massless = true
end
end
-- Welds everything to the character
for _, MorphCharPart in pairs(NewMorph:GetChildren()) do
if #MorphCharPart:GetChildren() <= 1 then MorphCharPart:Destroy() continue end
local function WeldToMiddle(part)
local NewWeldConstraint = Instance.new("WeldConstraint")
NewWeldConstraint.Parent = MorphCharPart._Middle
NewWeldConstraint.Part0 = MorphCharPart._Middle
NewWeldConstraint.Part1 = part
end
local MorphCharPartWeld = Instance.new("Motor6D")
MorphCharPartWeld.Parent = MorphCharPart._Middle
MorphCharPartWeld.Part1 = MorphCharPart._Middle
MorphCharPartWeld.Part0 = Char:FindFirstChild(MorphCharPart.Name)
for _, v in pairs(MorphCharPart:GetChildren()) do
if v.Name == "_Middle" then continue end
if v:IsA("BasePart") then
WeldToMiddle(v)
elseif v:IsA("Model") then
for _, k in pairs(v:GetDescendants()) do
if not k:IsA("BasePart") then continue end
WeldToMiddle(k)
end
end
end
MorphCharPart._Middle.Transparency = 1
MorphCharPart.Parent = MorphContainer
end
-- Sets PlayerName billboard to player's name
Char.Head.TagsBillboard.PlayerName.Text = Player.Name
Char.Head.TagsBillboard.PlayerRank.TextColor3 = Player.Team.TeamColor.Color
-- Sets PlayerRank billboard to player's group rank.
GetGroupRank(Player):andThen(function(RankName)
Char.Head.TagsBillboard.PlayerRank.Text = RankName
end)
Char.Name = Player.Name
Char.Parent = workspace
Player.Character = Char
Char.HumanoidRootPart:SetNetworkOwner(Player)
Char.Humanoid.Died:Connect(function()
print("Died")
for _, v in pairs(Char:GetDescendants()) do
if v:IsA("BasePart") then v:SetNetworkOwner(Player) end
end
end)
resolve()
end)
end
Please help!