Why is this error occurring?
- Occurs when the body part of the character is removed or disappeared.
local Players = game:GetService("Players")
local function ConnectLimbs(char)
for i, limb in pairs(char:GetChildren()) do
if limb:IsA("BasePart") then
local atch0, atch1, atch2, atch3, atch4, atch5
if limb.Name == "Head" then
atch0 = char and char:FindFirstChild("Head"):FindFirstChild("NeckRigAttachment")
atch1 = char and char:FindFirstChild("UpperTorso"):FindFirstChild("NeckRigAttachment")
elseif limb.Name == "UpperTorso" then
atch0 = char and char:FindFirstChild("UpperTorso"):FindFirstChild("WaistRigAttachment")
atch1 = char and char:FindFirstChild("LowerTorso"):FindFirstChild("WaistRigAttachment")
atch2 = char and char:FindFirstChild("UpperTorso"):FindFirstChild("LeftShoulderRigAttachment")
atch3 = char and char:FindFirstChild("LeftUpperArm"):FindFirstChild("LeftShoulderRigAttachment")
atch4 = char and char:FindFirstChild("UpperTorso"):FindFirstChild("RightShoulderRigAttachment")
atch5 = char and char:FindFirstChild("RightUpperArm"):FindFirstChild("RightShoulderRigAttachment")
elseif limb.Name == "LowerTorso" then
atch0 = char and char:FindFirstChild("LowerTorso"):FindFirstChild("LeftHipRigAttachment")
atch1 = char and char:FindFirstChild("LeftUpperLeg"):FindFirstChild("LeftHipRigAttachment")
atch2 = char and char:FindFirstChild("LowerTorso"):FindFirstChild("RightHipRigAttachment")
atch3 = char and char:FindFirstChild("RightUpperLeg"):FindFirstChild("RightHipRigAttachment")
elseif limb.Name == "LeftUpperLeg" then
atch0 = char and char:FindFirstChild("LeftUpperLeg"):FindFirstChild("LeftKneeRigAttachment")
atch1 = char and char:FindFirstChild("LeftLowerLeg"):FindFirstChild("LeftKneeRigAttachment")
elseif limb.Name == "RightUpperLeg" then
atch0 = char and char:FindFirstChild("RightUpperLeg"):FindFirstChild("RightKneeRigAttachment")
atch1 = char and char:FindFirstChild("RightLowerLeg"):FindFirstChild("RightKneeRigAttachment")
elseif limb.Name == "LeftLowerLeg" then
atch0 = char and char:FindFirstChild("LeftLowerLeg"):FindFirstChild("LeftAnkleRigAttachment")
atch1 = char and char:FindFirstChild("LeftFoot"):FindFirstChild("LeftAnkleRigAttachment")
elseif limb.Name == "RightLowerLeg" then
atch0 = char and char:FindFirstChild("RightLowerLeg"):FindFirstChild("RightAnkleRigAttachment")
atch1 = char and char:FindFirstChild("RightFoot"):FindFirstChild("RightAnkleRigAttachment")
elseif limb.Name == "LeftUpperArm" then
atch0 = char and char:FindFirstChild("LeftUpperArm"):FindFirstChild("LeftElbowRigAttachment")
atch1 = char and char:FindFirstChild("LeftLowerArm"):FindFirstChild("LeftElbowRigAttachment")
elseif limb.Name == "RightUpperArm" then
atch0 = char and char:FindFirstChild("RightUpperArm"):FindFirstChild("RightElbowRigAttachment")
atch1 = char and char:FindFirstChild("RightLowerArm"):FindFirstChild("RightElbowRigAttachment")
elseif limb.Name == "LeftLowerArm" then
atch0 = char and char:FindFirstChild("LeftLowerArm"):FindFirstChild("LeftWristRigAttachment")
atch1 = char and char:FindFirstChild("LeftHand"):FindFirstChild("LeftWristRigAttachment")
elseif limb.Name == "RightLowerArm" then
atch0 = char and char:FindFirstChild("RightLowerArm"):FindFirstChild("RightWristRigAttachment")
atch1 = char and char:FindFirstChild("RightHand"):FindFirstChild("RightWristRigAttachment")
end
if atch0 and atch1 then
local ballInSocket = Instance.new("BallSocketConstraint", limb)
ballInSocket.Attachment0 = atch0
ballInSocket.Attachment1 = atch1
end
if atch2 and atch3 then
local ballInSocket = Instance.new("BallSocketConstraint", limb)
ballInSocket.Attachment0 = atch2
ballInSocket.Attachment1 = atch3
end
if atch4 and atch5 then
local ballInSocket = Instance.new("BallSocketConstraint", limb)
ballInSocket.Attachment0 = atch4
ballInSocket.Attachment1 = atch5
end
elseif limb:IsA("Accessory") then
local h = limb:FindFirstChild("Handle")
if h then
local part0 = char and char:FindFirstChild("Head")
local atch = h:FindFirstChildOfClass("Attachment")
if atch.Name == "HatAttachment" or atch.Name == "FaceFrontAttachment" then
part0 = char and char:FindFirstChild("Head")
local fs = part0:FindFirstChild("face")
if not fs then
local decal = Instance.new("Decal", part0)
decal.Texture = "http://www.roblox.com/asset/?id=4841508676"
return
end
if fs then
fs:Destroy()
local decal = Instance.new("Decal", part0)
decal.Texture = "http://www.roblox.com/asset/?id=4841508676"
end
end
local ap = Instance.new("AlignPosition", part0)
if part0 == char and char:FindFirstChild("Head") then
ap.Attachment1 = char and char:FindFirstChild("Head"):FindFirstChild(atch.Name)
ap.Attachment0 = atch
ap.RigidityEnabled = true
ap.Responsiveness = 70
end
local ao = Instance.new("AlignOrientation", part0)
if part0 == char and char:FindFirstChild("Head") then
ao.Attachment1 = char and char:FindFirstChild("Head"):FindFirstChild(atch.Name)
ao.Attachment0 = atch
ao.RigidityEnabled = true
ao.Responsiveness = 70
end
end
end
end
end
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local humanoid = char and char:FindFirstChildWhichIsA("Humanoid") or char and char:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
ConnectLimbs(char)
end)
end)
end)