So this is part of a ragdoll script that goes into the character. It's shortened so that way it only includes the parts that make the error.

wait() 
local desc = script.Parent:GetDescendants()

function createconstraint(properties)
    local constraint = Instance.new(properties[1].Change)
    table.remove(properties,1)
    for i,v in pairs(properties)do        
    constraint[v.Property] = v.Change
    end    
end

for i,v in pairs(desc) do
if v:IsA("Motor6D")then 
local jointnames = {"Knee","Elbow","Waist","Shoulder","Root","Hip","Ankle","Neck","Wrist"}

    local elbowproperties = {
        {Property="ClassName",Change="HingeConstraint"};
        {Property="Parent",Change=v.Parent};
        {Property="Name",Change=v.Name.."HingeConstraint"};
        {Property="Attachment0",Change=reference0.Parent:FindFirstChild(v.Name.."BallSocketAttachment")};
        {Property="Attachment1",Change=reference1.Parent:FindFirstChild(v.Name.."BallSocketAttachment")};
        {Property="LimitsEnabled",Change=true};
        {Property="LowerAngle",Change=0};
        {Property="UpperAngle",Change= -180};
        }

for a,b in pairs(jointnames) do
  if string.match(v.Name,b)then
  createconstraint(string.lower(b).."properties")
  break
  end
end 
end
end