I have a morph function for my game, which works perfectly fine in studio. However, when used in a live game, it sometimes kills the player. I can’t figure out why it is killing some but not others or why it only happens in game.
function PlayerService:Morph(morph: string)
morph = string.lower(morph)
if (self.morph == morph) then
return
end
morph = script.Morphs:FindFirstChild(morph)
if (not morph) then
return warn('Morph "' .. morph .. '" does not exist!')
end
if (not self.Character) or (not self.Character.PrimaryPart) then
return
end
self.morph = morph
local description = CreateMorphDescription(self.Humanoid:FindFirstChildOfClass("HumanoidDescription"))
self.Humanoid:ApplyDescription(description)
self.Humanoid:UnequipTools()
for i, v in self.Character:GetChildren() do
if v:IsA("BasePart") then
v.Anchored = true
elseif v:IsA("BodyColors") then--or v:IsA("Clothing") or v:IsA("ShirtGraphic") or v:IsA("Accessory") then
v:Destroy()
end
end
for i, v in morph:GetChildren() do
local part = self.Character:FindFirstChild(v.Name)
if part then
local clone = v:Clone()
if v.Name == "Head" then
clone.Color = description["HeadColor"]
end
clone.CFrame = part.CFrame
clone.Parent = self.Character
for a, b in part:GetChildren() do
b.Parent = clone
end
for a, b in self.Character:GetDescendants() do
if b:IsA("Motor6D") then
if b and (b.Part0 or b.Part1) then
if b.Part0 == part then
b.Part0 = clone
end
if b.Part1 == part then
b.Part1 = clone
end
end
end
end
part:Destroy()
end
end
for i, v in self.Character:GetChildren() do
if v:IsA("BasePart") then
v.Anchored = false
end
end
self.morph = morph
task.delay(5,function()
description:Destroy()
end)
end