Advertisement
EconomicSerg

Roblox Ragdoll Script Advanced

Dec 31st, 2020
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.43 KB | None | 0 0
  1. game:GetService("Players").PlayerAdded:Connect(function (plr)
  2.     plr.CharacterAdded:Connect(function (char)
  3.         local humanoid = char:WaitForChild("Humanoid")
  4.         humanoid.Died:Connect(function ()
  5.             if char:FindFirstChild("HumanoidRootPart") then
  6.                
  7.                 local rig = humanoid.RigType
  8.                 local root = char.HumanoidRootPart
  9.                
  10.                 humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
  11.                 humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
  12.                 root.Anchored = true
  13.                 root.CanCollide = false
  14.                
  15.                 if rig == Enum.HumanoidRigType.R6 then
  16.                    
  17.                     local function stick (cl, p0, p1, c0, c1, p)
  18.                         local a = Instance.new(cl)
  19.                         a.Part0 = p0
  20.                         a.Part1 = p1
  21.                         a.C0 = c0
  22.                         a.C1 = c1
  23.                         a.Parent = p
  24.                     end
  25.                    
  26.                     local function createLimb (p, char)
  27.                         local limb = Instance.new("Part", char)
  28.                         limb.formFactor = "Symmetric"
  29.                         limb.Size = Vector3.new(1, 1, 1)
  30.                         limb.Transparency = 1
  31.                         limb.CFrame = p.CFrame * CFrame.new(0, -0.5, 0)
  32.                         local W = Instance.new("Weld")
  33.                         W.Part0 = p
  34.                         W.Part1 = limb
  35.                         W.C0 = CFrame.new(0, -.5, 0)
  36.                         W.Parent = p
  37.                     end
  38.                    
  39.                     char.Archivable = true
  40.                     local charClone = char:Clone()
  41.                     charClone.Name = plr.Name .. "-2"
  42.                     char.Archivable = false
  43.                    
  44.                     for _,v in pairs(charClone:GetChildren()) do
  45.                         if v:IsA("BasePart") then
  46.                             for _,vv in pairs(v:GetChildren()) do
  47.                                 if vv:IsA("Weld") or vv:IsA("Motor6D") then
  48.                                     vv:Destroy()
  49.                                 end
  50.                             end
  51.                         elseif v:IsA("Script") or v:IsA("LocalScript") or v:IsA("Tool") then
  52.                             v:Destroy()
  53.                         end
  54.                     end
  55.                    
  56.                     local hum2 = charClone.Humanoid
  57.                     hum2.Name = "Humanoid2"
  58.                     hum2.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
  59.                    
  60.                     wait(.1)
  61.                     for _,v in pairs(char:GetChildren()) do
  62.                         if v:IsA("BasePart") or v:IsA("Accoutrement") or v:IsA("Script") or v:IsA("LocalScript") then
  63.                             v:Destroy()
  64.                         end
  65.                     end
  66.                    
  67.                     char = charClone
  68.                     local torso = char.Torso
  69.                    
  70.                     for _,p in pairs(char:GetChildren()) do
  71.                         if p:IsA("BasePart") then
  72.                             if p.Name == "Head" then
  73.                                 stick("Weld", torso, char.Head, CFrame.new(0, 1.5, 0), CFrame.new(), torso)
  74.                             elseif p.Name == "Torso" then
  75.                                 local Bar = Instance.new("Part")
  76.                                 Bar.TopSurface = 0
  77.                                 Bar.BottomSurface = 0
  78.                                 Bar.formFactor = "Symmetric"
  79.                                 Bar.Size = Vector3.new(1, 1, 1)
  80.                                 Bar.Transparency = 1
  81.                                 Bar.CFrame = p.CFrame * CFrame.new(0, .5, 0)
  82.                                 Bar.Parent = char
  83.                                 local Weld = Instance.new("Weld")
  84.                                 Weld.Part0 = p
  85.                                 Weld.Part1 = Bar
  86.                                 Weld.C0 = CFrame.new(0, .5, 0)
  87.                                 Weld.Parent = p
  88.                             elseif p.Name == "Right Arm" then
  89.                                 p.CFrame = torso.CFrame * CFrame.new(1.5, 0, 0)
  90.                                 stick("Glue", torso, p, CFrame.new(1.5, .5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0), CFrame.new(-0, .5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0), torso)
  91.                                 createLimb(p, char)
  92.                             elseif p.Name == "Left Arm" then
  93.                                 p.CFrame = torso.CFrame * CFrame.new(-1.5, 0, 0)
  94.                                 stick("Glue", torso, p, CFrame.new(-1.5, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0), CFrame.new(0, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0), torso)
  95.                                 createLimb(p, char)
  96.                             elseif p.Name == "Right Leg" then
  97.                                 p.CFrame = torso.CFrame * CFrame.new(.5, -2, 0)
  98.                                 stick("Glue", torso, p, CFrame.new(.5, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0), CFrame.new(0, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0), torso)
  99.                                 createLimb(p, char)
  100.                             elseif p.Name == "Left Leg" then
  101.                                 p.CFrame = torso.CFrame * CFrame.new(-.5, -2, 0)
  102.                                 stick("Glue", torso, p, CFrame.new(-.5, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0), CFrame.new(-0, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0), torso)
  103.                                 createLimb(p, char)
  104.                             end
  105.                         elseif p:IsA("Accoutrement") and p.Handle then
  106.                             stick("Weld", torso, char.Head, CFrame.new(0, 1.5, 0), CFrame.new(), char.Head)
  107.                         end
  108.                     end
  109.                        
  110.                     char.Parent = workspace
  111.                     game:GetService("Debris"):AddItem(char, 6)
  112.                 else
  113.  
  114.                     local function recurse (root, callback, i)
  115.                         for _,c in pairs(root:GetChildren()) do
  116.                            
  117.                             i = i + 1
  118.                             callback(i, c)
  119.                            
  120.                             if #c:GetChildren() > 0 then
  121.                                 i = recurse(c, callback, i)
  122.                             end
  123.                         end
  124.                        
  125.                         return i
  126.                     end
  127.                    
  128.                     local function ragdollJoint (p0, p1, att, class, properties)
  129.                        
  130.                         att = att .. "RigAttachment"
  131.                        
  132.                         local constraint = Instance.new(class .. "Constraint")
  133.                         constraint.Attachment0 = p0:FindFirstChild(att)
  134.                         constraint.Attachment1 = p1:FindFirstChild(att)
  135.                         constraint.Name = "RagdollConstraint" .. p1.Name
  136.                        
  137.                         for _,pData in pairs(properties or {}) do
  138.                             constraint[pData[1]] = pData[2]
  139.                         end
  140.                        
  141.                         constraint.Parent = char
  142.                     end
  143.                    
  144.                     local function getAttachment0 (attName)
  145.                         for _,c in pairs(char:GetChildren()) do
  146.                             if c:FindFirstChild(attName) then
  147.                                 return c:FindFirstChild(attName)
  148.                             end
  149.                         end
  150.                     end
  151.                    
  152.                     recurse(char, function(_, v)
  153.                         if v:IsA("Attachment") then
  154.                             v.Axis = Vector3.new(1, 0, 0)
  155.                             v.SecondaryAxis = Vector3.new(0, 1, 0)
  156.                             v.Orientation = Vector3.new(0, 0, 0)
  157.                         end
  158.                     end, 0)
  159.                            
  160.                     for _,c in pairs(char:GetChildren()) do
  161.                         if c:IsA("Accoutrement") then
  162.                             for _,part in pairs(c:GetChildren()) do
  163.                                 if part:IsA("BasePart") then
  164.                                    
  165.                                     local attachment1 = part:FindFirstChildOfClass("Attachment")
  166.                                     local attachment0 = getAttachment0(attachment1.Name)
  167.                                    
  168.                                     if attachment0 and attachment1 then
  169.                                        
  170.                                         local constraint = Instance.new("HingeConstraint")
  171.                                         constraint.Attachment0 = attachment0
  172.                                         constraint.Attachment1 = attachment1
  173.                                         constraint.LimitsEnabled = true
  174.                                         constraint.UpperAngle = 0
  175.                                         constraint.LowerAngle = 0
  176.                                         constraint.Parent = char
  177.                                     end
  178.                                 end
  179.                             end
  180.                         end
  181.                     end
  182.                    
  183.                     if rig == Enum.HumanoidRigType.R6 then
  184.                        
  185.                         ragdollJoint(char.Torso, char.Head, "Neck", "BallSocket", {
  186.                             {"LimitsEnabled", true};
  187.                             {"UpperAngle", 0};
  188.                         })
  189.                        
  190.                         ragdollJoint(char.Torso, char["Left Arm"], "LeftShoulder", "BallSocket")
  191.                         ragdollJoint(char.Torso, char["Right Arm"], "RightShoulder", "BallSocket")
  192.                         ragdollJoint(char.Torso, char["Left Leg"], "LeftTrunk", "BallSocket")
  193.                         ragdollJoint(char.Torso, char["Right Leg"], "RightTrunk", "BallSocket")
  194.                        
  195.                     elseif rig == Enum.HumanoidRigType.R15 then
  196.        
  197.                         ragdollJoint(char.LowerTorso, char.UpperTorso, "Waist", "BallSocket", {
  198.                             {"LimitsEnabled", true};
  199.                             {"UpperAngle", 5};
  200.                         })
  201.                        
  202.                         ragdollJoint(char.UpperTorso, char.Head, "Neck", "BallSocket", {
  203.                             {"LimitsEnabled", true};
  204.                             {"UpperAngle", 15};
  205.                         })
  206.                        
  207.                         local handProperties = {
  208.                             {"LimitsEnabled", true};
  209.                             {"UpperAngle", 0};
  210.                             {"LowerAngle", 0};
  211.                         }
  212.                        
  213.                         ragdollJoint(char.LeftLowerArm, char.LeftHand, "LeftWrist", "Hinge", handProperties)
  214.                         ragdollJoint(char.RightLowerArm, char.RightHand, "RightWrist", "Hinge", handProperties)
  215.                        
  216.                         local shinProperties = {
  217.                             {"LimitsEnabled", true};
  218.                             {"UpperAngle", 0};
  219.                             {"LowerAngle", -75};
  220.                         }
  221.                        
  222.                         ragdollJoint(char.LeftUpperLeg, char.LeftLowerLeg, "LeftKnee", "Hinge", shinProperties)
  223.                         ragdollJoint(char.RightUpperLeg, char.RightLowerLeg, "RightKnee", "Hinge", shinProperties)
  224.                        
  225.                         local footProperties = {
  226.                             {"LimitsEnabled", true};
  227.                             {"UpperAngle", 15};
  228.                             {"LowerAngle", -45};
  229.                         }
  230.                        
  231.                         ragdollJoint(char.LeftLowerLeg, char.LeftFoot, "LeftAnkle", "Hinge", footProperties)
  232.                         ragdollJoint(char.RightLowerLeg, char.RightFoot, "RightAnkle", "Hinge", footProperties)
  233.                        
  234.                         ragdollJoint(char.UpperTorso, char.LeftUpperArm, "LeftShoulder", "BallSocket")
  235.                         ragdollJoint(char.LeftUpperArm, char.LeftLowerArm, "LeftElbow", "BallSocket")
  236.                         ragdollJoint(char.UpperTorso, char.RightUpperArm, "RightShoulder", "BallSocket")
  237.                         ragdollJoint(char.RightUpperArm, char.RightLowerArm, "RightElbow", "BallSocket")
  238.                         ragdollJoint(char.LowerTorso, char.LeftUpperLeg, "LeftHip", "BallSocket")
  239.                         ragdollJoint(char.LowerTorso, char.RightUpperLeg, "RightHip", "BallSocket")
  240.                     end
  241.                 end
  242.             end
  243.         end)
  244.     end)
  245. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement