Advertisement
dubleeyrblxx

Ragdoll on death -- Roblox

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