Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.13 KB | None | 0 0
  1. wait()
  2. if script.Parent.Humanoid.RigType ~= Enum.HumanoidRigType.R15 then
  3.     game.Debris:AddItem(script,1)
  4. else
  5.  
  6. local character = script.Parent
  7.  
  8. function recurse(root,callback,i)
  9.     i= i or 0
  10.     for _,v in pairs(root:GetChildren()) do
  11.         i = i + 1
  12.         callback(i,v)
  13.        
  14.         if #v:GetChildren() > 0 then
  15.             i = recurse(v,callback,i)
  16.         end
  17.     end
  18.    
  19.     return i
  20. end
  21.  
  22. function ragdollJoint(part0, part1, attachmentName, className, properties)
  23.     attachmentName = attachmentName.."RigAttachment"
  24.     local constraint = Instance.new(className.."Constraint")
  25.     constraint.Attachment0 = part0:FindFirstChild(attachmentName)
  26.     constraint.Attachment1 = part1:FindFirstChild(attachmentName)
  27.     constraint.Name = "RagdollConstraint"..part1.Name
  28.    
  29.     for _,propertyData in next,properties or {} do
  30.         constraint[propertyData[1]] = propertyData[2]
  31.     end
  32.    
  33.     constraint.Parent = character
  34. end
  35.  
  36. function getAttachment0(attachmentName)
  37.     for _,child in next,character:GetChildren() do
  38.         local attachment = child:FindFirstChild(attachmentName)
  39.         if attachment then
  40.             return attachment
  41.         end
  42.     end
  43. end
  44.  
  45. character:WaitForChild("Humanoid").Died:connect(function()
  46.     local camera = workspace.CurrentCamera
  47.     if camera.CameraSubject == character.Humanoid then
  48.         camera.CameraSubject = character.UpperTorso
  49.     end
  50.     character.HumanoidRootPart.Anchored = true
  51.     character.HumanoidRootPart.CanCollide = false
  52.  
  53.     recurse(character, function(_,v)
  54.         if v:IsA("Attachment") then
  55.             v.Axis = Vector3.new(0, 1, 0)
  56.             v.SecondaryAxis = Vector3.new(0, 0, 1)
  57.             v.Rotation = Vector3.new(0, 0, 0)
  58.         end
  59.     end)
  60.    
  61.     for _,child in next,character:GetChildren() do
  62.         if child:IsA("Accoutrement") then
  63.             for _,part in next,child:GetChildren() do
  64.                 if part:IsA("BasePart") then
  65.                     part.Parent = character
  66.                     child:remove()
  67.                     local attachment1 = part:FindFirstChildOfClass("Attachment")
  68.                     local attachment0 = getAttachment0(attachment1.Name)
  69.                     if attachment0 and attachment1 then
  70.                         local constraint = Instance.new("HingeConstraint")
  71.                         constraint.Attachment0 = attachment0
  72.                         constraint.Attachment1 = attachment1
  73.                         constraint.LimitsEnabled = true
  74.                         constraint.UpperAngle = 0
  75.                         constraint.LowerAngle = 0
  76.                         constraint.Parent = character
  77.                     end
  78.                 end
  79.             end
  80.         end
  81.     end
  82.    
  83.     ragdollJoint(character.LowerTorso, character.UpperTorso, "Waist", "BallSocket", {
  84.         {"LimitsEnabled",true};
  85.         {"UpperAngle",5};
  86.     })
  87.     ragdollJoint(character.UpperTorso, character.Head, "Neck", "BallSocket", {
  88.         {"LimitsEnabled",true};
  89.         {"UpperAngle",15};
  90.     })
  91.    
  92.     local handProperties = {
  93.         {"LimitsEnabled", true};
  94.         {"UpperAngle",0};
  95.         {"LowerAngle",0};
  96.     }
  97.     ragdollJoint(character.LeftLowerArm, character.LeftHand, "LeftWrist", "Hinge", handProperties)
  98.     ragdollJoint(character.RightLowerArm, character.RightHand, "RightWrist", "Hinge", handProperties)
  99.    
  100.     local shinProperties = {
  101.         {"LimitsEnabled", true};
  102.         {"UpperAngle", 0};
  103.         {"LowerAngle", -75};
  104.     }
  105.     ragdollJoint(character.LeftUpperLeg, character.LeftLowerLeg, "LeftKnee", "Hinge", shinProperties)
  106.     ragdollJoint(character.RightUpperLeg, character.RightLowerLeg, "RightKnee", "Hinge", shinProperties)
  107.    
  108.     local footProperties = {
  109.         {"LimitsEnabled", true};
  110.         {"UpperAngle", 15};
  111.         {"LowerAngle", -45};
  112.     }
  113.     ragdollJoint(character.LeftLowerLeg, character.LeftFoot, "LeftAnkle", "Hinge", footProperties)
  114.     ragdollJoint(character.RightLowerLeg, character.RightFoot, "RightAnkle", "Hinge", footProperties)
  115.    
  116.     ragdollJoint(character.UpperTorso, character.LeftUpperArm, "LeftShoulder", "BallSocket")
  117.     ragdollJoint(character.LeftUpperArm, character.LeftLowerArm, "LeftElbow", "BallSocket")
  118.     ragdollJoint(character.UpperTorso, character.RightUpperArm, "RightShoulder", "BallSocket")
  119.     ragdollJoint(character.RightUpperArm, character.RightLowerArm, "RightElbow", "BallSocket")
  120.     ragdollJoint(character.LowerTorso, character.LeftUpperLeg, "LeftHip", "BallSocket")
  121.     ragdollJoint(character.LowerTorso, character.RightUpperLeg, "RightHip", "BallSocket")
  122.     wait(0.6)
  123.     local Stuff = character:GetChildren()
  124.     for i = 1, #Stuff do
  125.         if Stuff[i]:IsA("MeshPart") or Stuff[i]:IsA("Part") then
  126.             Stuff[i].Anchored = true
  127.         end
  128.     end
  129. end)
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement