Advertisement
DylanD2003

Untitled

Sep 16th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. game.Players.PlayerAdded:connect(function(player)
  2. player.CharacterAdded:connect(function(character)
  3. script.RagdollClient:Clone().Parent = character
  4.  
  5. character:WaitForChild("Humanoid").Died:connect(function()
  6. character.UpperTorso:SetNetworkOwner(player)
  7.  
  8. local character = script.Parent
  9.  
  10. function recurse(root,callback,i)
  11. i= i or 0
  12. for _,v in pairs(root:GetChildren()) do
  13. i = i + 1
  14. callback(i,v)
  15.  
  16. if #v:GetChildren() > 0 then
  17. i = recurse(v,callback,i)
  18. end
  19. end
  20.  
  21. return i
  22. end
  23.  
  24. function ragdollJoint(part0, part1, attachmentName, className, properties)
  25. attachmentName = attachmentName.."RigAttachment"
  26. local constraint = Instance.new(className.."Constraint")
  27. constraint.Attachment0 = part0:FindFirstChild(attachmentName)
  28. constraint.Attachment1 = part1:FindFirstChild(attachmentName)
  29. constraint.Name = "RagdollConstraint"..part1.Name
  30.  
  31. for _,propertyData in next,properties or {} do
  32. constraint[propertyData[1]] = propertyData[2]
  33. end
  34.  
  35. constraint.Parent = character
  36. end
  37.  
  38. function getAttachment0(attachmentName)
  39. for _,child in next,character:GetChildren() do
  40. local attachment = child:FindFirstChild(attachmentName)
  41. if attachment then
  42. return attachment
  43. end
  44. end
  45. end
  46.  
  47. character:WaitForChild("Humanoid").Died:connect(function()
  48. local camera = workspace.CurrentCamera
  49. if camera.CameraSubject == character.Humanoid then--If developer isn't controlling camera
  50. camera.CameraSubject = character.UpperTorso
  51. end
  52.  
  53. --Make it so ragdoll can't collide with invisible HRP, but don't let HRP fall through map and be destroyed in process
  54. character.HumanoidRootPart.Anchored = true
  55. character.HumanoidRootPart.CanCollide = false
  56.  
  57. --Helps to fix constraint spasms
  58. recurse(character, function(_,v)
  59. if v:IsA("Attachment") then
  60. v.Axis = Vector3.new(0, 1, 0)
  61. v.SecondaryAxis = Vector3.new(0, 0, 1)
  62. v.Rotation = Vector3.new(0, 0, 0)
  63. end
  64. end)
  65.  
  66. --Re-attach hats
  67. for _,child in next,character:GetChildren() do
  68. if child:IsA("Accoutrement") then
  69. --Loop through all parts instead of only checking for one to be forwards-compatible in the event
  70. --ROBLOX implements multi-part accessories
  71. for _,part in next,child:GetChildren() do
  72. if part:IsA("BasePart") then
  73. local attachment1 = part:FindFirstChildOfClass("Attachment")
  74. local attachment0 = getAttachment0(attachment1.Name)
  75. if attachment0 and attachment1 then
  76. --Shouldn't use constraints for this, but have to because of a ROBLOX idiosyncrasy where
  77. --joints connecting a character are perpetually deleted while the character is dead
  78. local constraint = Instance.new("HingeConstraint")
  79. constraint.Attachment0 = attachment0
  80. constraint.Attachment1 = attachment1
  81. constraint.LimitsEnabled = true
  82. constraint.UpperAngle = 0 --Simulate weld by making it difficult for constraint to move
  83. constraint.LowerAngle = 0
  84. constraint.Parent = character
  85. end
  86. end
  87. end
  88. end
  89. end
  90.  
  91. ragdollJoint(character.LowerTorso, character.UpperTorso, "Waist", "BallSocket", {
  92. {"LimitsEnabled",true};
  93. {"UpperAngle",5};
  94. })
  95. ragdollJoint(character.UpperTorso, character.Head, "Neck", "BallSocket", {
  96. {"LimitsEnabled",true};
  97. {"UpperAngle",15};
  98. })
  99.  
  100. local handProperties = {
  101. {"LimitsEnabled", true};
  102. {"UpperAngle",0};
  103. {"LowerAngle",0};
  104. }
  105. ragdollJoint(character.LeftLowerArm, character.LeftHand, "LeftWrist", "Hinge", handProperties)
  106. ragdollJoint(character.RightLowerArm, character.RightHand, "RightWrist", "Hinge", handProperties)
  107.  
  108. local shinProperties = {
  109. {"LimitsEnabled", true};
  110. {"UpperAngle", 0};
  111. {"LowerAngle", -75};
  112. }
  113. ragdollJoint(character.LeftUpperLeg, character.LeftLowerLeg, "LeftKnee", "Hinge", shinProperties)
  114. ragdollJoint(character.RightUpperLeg, character.RightLowerLeg, "RightKnee", "Hinge", shinProperties)
  115.  
  116. local footProperties = {
  117. {"LimitsEnabled", true};
  118. {"UpperAngle", 15};
  119. {"LowerAngle", -45};
  120. }
  121. ragdollJoint(character.LeftLowerLeg, character.LeftFoot, "LeftAnkle", "Hinge", footProperties)
  122. ragdollJoint(character.RightLowerLeg, character.RightFoot, "RightAnkle", "Hinge", footProperties)
  123.  
  124. --TODO fix ability for socket to turn backwards whenn ConeConstraints are shipped
  125. ragdollJoint(character.UpperTorso, character.LeftUpperArm, "LeftShoulder", "BallSocket")
  126. ragdollJoint(character.LeftUpperArm, character.LeftLowerArm, "LeftElbow", "BallSocket")
  127. ragdollJoint(character.UpperTorso, character.RightUpperArm, "RightShoulder", "BallSocket")
  128. ragdollJoint(character.RightUpperArm, character.RightLowerArm, "RightElbow", "BallSocket")
  129. ragdollJoint(character.LowerTorso, character.LeftUpperLeg, "LeftHip", "BallSocket")
  130. ragdollJoint(character.LowerTorso, character.RightUpperLeg, "RightHip", "BallSocket")
  131. end)
  132. end)
  133. end)
  134. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement