KrYn0MoRe

ragdoll system

Jun 13th, 2020
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.26 KB | None | 0 0
  1. function limb_collide(obj,mode)
  2.     if (obj:IsA("UnionOperation") or obj:IsA("BasePart")) and not obj:FindFirstChild('limb') then else return end
  3.     local exists = pcall(game:GetService("PhysicsService").GetCollisionGroupId, game:GetService("PhysicsService"), 'Limb Collide')
  4.     if not exists then
  5.         game:GetService("PhysicsService"):CreateCollisionGroup('Limb Collide')
  6.     end
  7.     game:GetService("PhysicsService"):CollisionGroupSetCollidable('Limb Collide','Limb Collide',false)
  8.     --
  9.     local t = {}
  10.     --
  11.     local cb = Instance.new("Part")
  12.     cb.Name = 'limb'
  13.     cb.Transparency = 1
  14.     cb.CanCollide = true
  15.     cb.Anchored = false
  16.     cb.CFrame = obj.CFrame
  17.     cb.Size = obj.Size
  18.     cb.Massless = true
  19.     cb.Locked = true
  20.     game:GetService("PhysicsService"):SetPartCollisionGroup(cb,'Limb Collide')
  21.     game:GetService("PhysicsService"):SetPartCollisionGroup(obj,'Limb Collide')
  22.     local weld = Instance.new("Weld")
  23.     weld.Part0 = cb
  24.     weld.Part1 = obj
  25.     weld.Parent = cb
  26.     obj.Massless = true
  27.     obj.Anchored = false
  28.     if mode or obj:FindFirstChild("Dismembered") then
  29.         cb.Parent = obj -- .Parent
  30.     else
  31.         cb.Parent = script
  32.         table.insert(t,1,cb)
  33.     end
  34.     --
  35.     if not string.match(obj.Name:lower(),'torso') and not string.match(obj.Name:lower(),'rootpart') and not string.match(obj.Name:lower(),'head') then
  36.         local lv = Vector3.new() -- Vector3.new(cb.Size.X,0,cb.Size.Z)
  37.         local cb2 = Instance.new("Part")
  38.         cb2.Name = 'limb'
  39.         cb2.Transparency = 1
  40.         cb2.CanCollide = true
  41.         cb2.Anchored = false
  42.         cb2.CFrame = obj.CFrame
  43.         cb2.Size = lv
  44.         cb2.Massless = true
  45.         cb2.Locked = true
  46.         local weld2 = Instance.new("Weld")
  47.         weld2.Part0 = cb
  48.         weld2.Part1 = cb2
  49.         weld2.C1 = CFrame.new(0,(cb.Size.Y/2),0)
  50.         weld2.Parent = cb2
  51.         if mode or obj:FindFirstChild("Dismembered") then
  52.             cb2.Parent = obj -- .Parent
  53.         else
  54.             cb2.Parent = script
  55.             table.insert(t,1,cb2)
  56.         end
  57.     end
  58.     --
  59.     return t
  60. end
  61. function Ragdoll2(targchar,headless,insta,kill)
  62.     local pc = targchar
  63.     local targhum = pc:FindFirstChild("Humanoid")
  64.     local js,js2 = {},{}
  65.     for _,obj in pairs(pc:GetDescendants()) do
  66.         if obj:IsA("BasePart") or obj:IsA("UnionOperation") then
  67.             obj.Massless = true
  68.             obj.Locked = true
  69.         end
  70.     end
  71.     if kill == true then
  72.         pc.Archivable = true
  73.         local old_pc = pc
  74.         pc = pc:Clone()
  75.         for i,v in pairs(pc:GetDescendants()) do
  76.             limb_collide(v,true)
  77.             if v:IsA("ParticleEmitter") then
  78.                 v.Enabled = false
  79.             end
  80.             if v:IsA("SelectionBox") or v:IsA("BodyVelocity") or v:IsA("BodyPosition") or v:IsA("BodyAngularVelocity") or v:IsA("BodyForce") or v:IsA("BodyGyro") or v:IsA("BodyThrust") or v:IsA("BodyMover") then
  81.                 if v:IsA("BodyVelocity") then
  82.                     game:GetService("Debris"):AddItem(v,0.15)
  83.                 else
  84.                     v:Destroy()
  85.                 end
  86.             end
  87.             if (v:IsA("Script") and v.Name == 'Health') or (v:IsA("LocalScript") and v.Name == 'Animate') then
  88.                 v:Destroy()
  89.             end
  90.             if v:IsA("Humanoid") then
  91.                 v.BreakJointsOnDeath = false
  92.                 v.Health = 0
  93.                 v.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
  94.                 v.PlatformStand = true
  95.             end
  96.         end
  97.         for i,v in pairs(old_pc:GetDescendants()) do
  98.             if v:IsA("BasePart") or v:IsA("UnionOperation") or v:IsA("ForceField") or v:IsA("Accessory") or v:IsA("Decal") or v:IsA("Texture") or v:IsA("SurfaceGui") then
  99.                 v:destroy()
  100.             end
  101.             if v:IsA("Humanoid") then
  102.                 v.BreakJointsOnDeath = false
  103.                 v.Health = 0
  104.                 v.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
  105.                 v.PlatformStand = true
  106.             end
  107.         end
  108.         pc.Parent = workspace
  109.         game:GetService("Debris"):AddItem(pc,30)
  110.     end
  111.     --if kill and targhum:FindFirstChild("Ragdolled") then return; end;
  112.     local function check_weld_parts(v)
  113.         local r = false
  114.         if (((v.Part0.Name == 'Head' and not headless) or (v.Part0.Name ~= 'Head')) and (not string.match(v.Name:lower(),'root')) and not v.Part0:FindFirstChild("Dismembered")) and (((v.Part1.Name == 'Head' and not headless) or (v.Part1.Name ~= 'Head')) and not v.Part1:FindFirstChild("Dismembered")) then
  115.             r = true
  116.         end
  117.         return r
  118.     end
  119.     if pc ~= nil then
  120.         local targtorso = pc:FindFirstChild("Torso")
  121.         local targhum = pc:FindFirstChildOfClass("Humanoid")
  122.         targhum.BreakJointsOnDeath = false
  123.         if insta then
  124.             if targhum.RigType == Enum.HumanoidRigType.R6 and targtorso then
  125.                 for _,v in pairs(targtorso:GetDescendants()) do
  126.                     if (v:IsA('Motor6D') or v:IsA('Motor') or v:IsA('Weld')) then
  127.                         print(v.Name)
  128.                         if check_weld_parts(v) then    
  129.                             local att1,att2 = Instance.new("Attachment"),Instance.new("Attachment")
  130.                             att1.CFrame = v.C0
  131.                             att2.CFrame = v.C1
  132.                             att1.Parent = v.Part0
  133.                             att2.Parent = v.Part1
  134.                             local bis = Instance.new("BallSocketConstraint")
  135.                             bis.Attachment0 = att1
  136.                             bis.Attachment1 = att2
  137.                             bis.Parent = v.Parent
  138.                             table.insert(js,1,bis)
  139.                             if not kill then
  140.                                 table.insert(js2,1,{obj = v,par = v.Parent})
  141.                                 v.Parent = nil
  142.                             elseif kill then
  143.                                 v:Destroy()
  144.                             end
  145.                         end
  146.                     end
  147.                 end
  148.             elseif targhum.RigType == Enum.HumanoidRigType.R15 then
  149.                 for _,v in pairs(pc:GetDescendants()) do
  150.                     if (v:IsA('Motor6D') or v:IsA('Motor')) then
  151.                         if check_weld_parts(v) then      
  152.                             local att1,att2 = Instance.new("Attachment"),Instance.new("Attachment")
  153.                             att1.CFrame = v.C0
  154.                             att2.CFrame = v.C1
  155.                             att1.Parent = v.Part0
  156.                             att2.Parent = v.Part1
  157.                             local bis = Instance.new("BallSocketConstraint")
  158.                             bis.Attachment0 = att1
  159.                             bis.Attachment1 = att2
  160.                             bis.Parent = v.Parent
  161.                             table.insert(js,1,bis)
  162.                             if not kill then
  163.                                 table.insert(js2,1,{obj = v,par = v.Parent})
  164.                                 v.Parent = nil
  165.                             elseif kill then
  166.                                 v:Destroy()
  167.                             end
  168.                         end
  169.                     end
  170.                 end
  171.             end
  172.         elseif not insta then
  173.             hum.Died:Connect(function()
  174.                 if hum.RigType == Enum.HumanoidRigType.R6 and torso then
  175.                     for _,v in pairs(torso:GetDescendants()) do
  176.                         if (v:IsA('Motor6D') or v:IsA('Motor') or v:IsA('Weld')) then
  177.                             if check_weld_parts(v) then    
  178.                                 local att1,att2 = Instance.new("Attachment"),Instance.new("Attachment")
  179.                                 att1.CFrame = v.C0
  180.                                 att2.CFrame = v.C1
  181.                                 att1.Parent = v.Part0
  182.                                 att2.Parent = v.Part1
  183.                                 local bis = Instance.new("BallSocketConstraint")
  184.                                 bis.Attachment0 = att1
  185.                                 bis.Attachment1 = att2
  186.                                 bis.Parent = v.Parent
  187.                                 table.insert(js,1,bis)
  188.                                 if not kill then
  189.                                     table.insert(js2,1,{obj = v,par = v.Parent})
  190.                                     v.Parent = nil
  191.                                 elseif kill then
  192.                                     v:Destroy()
  193.                                 end
  194.                             end
  195.                         end
  196.                     end
  197.                 elseif hum.RigType == Enum.HumanoidRigType.R15 then
  198.                     for _,v in pairs(pc:GetDescendants()) do
  199.                         if (v:IsA('Motor6D') or v:IsA('Motor')) then
  200.                             if check_weld_parts(v) then    
  201.                                 local att1,att2 = Instance.new("Attachment"),Instance.new("Attachment")
  202.                                 att1.CFrame = v.C0
  203.                                 att2.CFrame = v.C1
  204.                                 att1.Parent = v.Part0
  205.                                 att2.Parent = v.Part1
  206.                                 local bis = Instance.new("BallSocketConstraint")
  207.                                 bis.Attachment0 = att1
  208.                                 bis.Attachment1 = att2
  209.                                 bis.Parent = v.Parent
  210.                                 table.insert(js,1,bis)
  211.                                 if not kill then
  212.                                     table.insert(js2,1,{obj = v,par = v.Parent})
  213.                                     v.Parent = nil
  214.                                 elseif kill then
  215.                                     v:Destroy()
  216.                                 end
  217.                             end
  218.                         end
  219.                     end
  220.                 end
  221.             end)
  222.         end
  223.     end
  224.     return js,js2
  225. end
  226. function Ragdoll(targchar,headless,insta,kill)
  227.     local pc = targchar
  228.     local targhum = pc:FindFirstChild("Humanoid")
  229.     local js,js2 = {},{}
  230.     for _,obj in pairs(pc:GetDescendants()) do
  231.         if obj:IsA("BasePart") or obj:IsA("UnionOperation") then
  232.             obj.Massless = true
  233.             obj.Locked = true
  234.         end
  235.     end
  236.     if kill == true then
  237.         pc.Archivable = true
  238.         local old_pc = pc
  239.         pc = pc:Clone()
  240.         for i,v in pairs(pc:GetDescendants()) do
  241.             limb_collide(v,true)
  242.             if v:IsA("ParticleEmitter") then
  243.                 v.Enabled = false
  244.             end
  245.             if v:IsA("SelectionBox") or v:IsA("BodyVelocity") or v:IsA("BodyPosition") or v:IsA("BodyAngularVelocity") or v:IsA("BodyForce") or v:IsA("BodyGyro") or v:IsA("BodyThrust") or v:IsA("BodyMover") then
  246.                 if v:IsA("BodyVelocity") then
  247.                     game:GetService("Debris"):AddItem(v,0.15)
  248.                 else
  249.                     v:Destroy()
  250.                 end
  251.             end
  252.             if (v:IsA("Script") and v.Name == 'Health') or (v:IsA("LocalScript") and v.Name == 'Animate') then
  253.                 v:Destroy()
  254.             end
  255.             if v:IsA("Humanoid") then
  256.                 v.BreakJointsOnDeath = false
  257.                 v.Health = 0
  258.                 v.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
  259.                 v.PlatformStand = true
  260.             end
  261.         end
  262.         for i,v in pairs(old_pc:GetDescendants()) do
  263.             if v:IsA("BasePart") or v:IsA("UnionOperation") or v:IsA("ForceField") or v:IsA("Accessory") or v:IsA("Decal") or v:IsA("Texture") or v:IsA("SurfaceGui") then
  264.                 v:destroy()
  265.             end
  266.             if v:IsA("Humanoid") then
  267.                 v.BreakJointsOnDeath = true
  268.                 v.Health = 0
  269.                 v.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
  270.                 v.PlatformStand = true
  271.             end
  272.         end
  273.         pc.Parent = workspace
  274.         game:GetService("Debris"):AddItem(pc,30)
  275.     end
  276.     --if kill and targhum:FindFirstChild("Ragdolled") then return; end;
  277.     if pc ~= nil then
  278.         local hum = pc:FindFirstChild'Humanoid'
  279.         local LArm = pc:FindFirstChild'Left Arm'
  280.         local RArm = pc:FindFirstChild'Right Arm'
  281.         local LLeg = pc:FindFirstChild'Left Leg'
  282.         local RLeg = pc:FindFirstChild'Right Leg'
  283.         local torso = pc:FindFirstChild'Torso'
  284.         local head = pc:FindFirstChild'Head'
  285.        
  286.        
  287.         local LUA = pc:FindFirstChild'LeftUpperArm'
  288.         local LLA = pc:FindFirstChild'LeftLowerArm'
  289.         local LH = pc:FindFirstChild'LeftHand'
  290.        
  291.         local RUA = pc:FindFirstChild'RightUpperArm'
  292.         local RLA = pc:FindFirstChild'RightLowerArm'
  293.         local RH = pc:FindFirstChild'RightHand'
  294.        
  295.         local LUL = pc:FindFirstChild'LeftUpperLeg'
  296.         local LLL = pc:FindFirstChild'LeftLowerLeg'
  297.         local LF = pc:FindFirstChild'LeftFoot'
  298.        
  299.         local RUL = pc:FindFirstChild'RightUpperLeg'
  300.         local RLL = pc:FindFirstChild'RightLowerLeg'
  301.         local RF = pc:FindFirstChild'RightFoot'
  302.        
  303.         local UT = pc:FindFirstChild'UpperTorso'
  304.         local LT = pc:FindFirstChild'LowerTorso'
  305.        
  306.         if hum and LArm and RArm and LLeg and RLeg and head then
  307.             hum.BreakJointsOnDeath = false
  308.             if insta then
  309.                 if hum.RigType==Enum.HumanoidRigType.R6 then
  310.                     for _,v in pairs(torso:GetDescendants()) do
  311.                         if (v:IsA('Motor6D') or v:IsA('Motor') or v:IsA('Weld') or v:IsA("BallSocketConstraint")) and (not string.match(v.Name:lower(),'root')) then
  312.                             if not kill then
  313.                                 table.insert(js2,1,{obj = v,par = v.Parent})
  314.                                 v.Parent = nil
  315.                             elseif kill then
  316.                                 v:Destroy()
  317.                             end
  318.                         end
  319.                     end
  320.                    local vis = false
  321.                    local vis2 = false
  322.                     if LArm and not LArm:FindFirstChild('Dismembered') then
  323.                        local at1 = Instance.new("Attachment")
  324.                        at1.Parent = torso
  325.                        at1.Visible = vis
  326.                        at1.Orientation = torso.Orientation + Vector3.new(0,180,0)
  327.                        at1.Position = Vector3.new(-1,1,0)
  328.                                        
  329.                        local at1p2 = Instance.new("Attachment")
  330.                        at1p2.Parent = LArm
  331.                        at1p2.Visible = vis
  332.                        at1p2.Orientation = LArm.Orientation + Vector3.new(0,180,0)
  333.                        at1p2.Position = Vector3.new(.5,1,0)
  334.                            
  335.                        local bis = Instance.new("BallSocketConstraint")
  336.                        bis.Parent = LArm
  337.                        bis.Attachment0 = at1
  338.                        bis.Attachment1 = at1p2
  339.                        bis.LimitsEnabled = true
  340.                        bis.UpperAngle = 15
  341.                        bis.Visible = vis2
  342.                        bis.TwistLimitsEnabled = true
  343.                        bis.UpperAngle = -45
  344.                        bis.TwistLowerAngle = -45
  345.                         table.insert(js,1,bis)
  346.                     end
  347.                     if RArm and not RArm:FindFirstChild('Dismembered') then    
  348.                         local at2 = Instance.new("Attachment")
  349.                         at2.Parent = torso
  350.                         at2.Visible = vis
  351.                         at2.Orientation = torso.Orientation + Vector3.new(0,0,0)
  352.                         at2.Position = Vector3.new(1,1,0)
  353.                                
  354.                         local at2p2 = Instance.new("Attachment")
  355.                         at2p2.Parent = RArm
  356.                         at2p2.Visible = vis
  357.                         at2p2.Orientation = RArm.Orientation + Vector3.new(0,0,0)
  358.                         at2p2.Position = Vector3.new(-.5,1,0)
  359.                        
  360.                         local bis2 = Instance.new("BallSocketConstraint")
  361.                         bis2.Parent = RArm
  362.                         bis2.Attachment0 = at2
  363.                         bis2.Attachment1 = at2p2
  364.                         bis2.LimitsEnabled = true
  365.                         bis2.UpperAngle = 15
  366.                         bis2.Visible = vis2
  367.                         bis2.TwistLimitsEnabled = true
  368.                         bis2.UpperAngle = -45
  369.                         bis2.TwistLowerAngle = -45
  370.                         table.insert(js,1,bis2)
  371.                     end
  372.                      if RLeg and not RLeg:FindFirstChild('Dismembered') then
  373.                         local at3 = Instance.new("Attachment")
  374.                         at3.Parent = torso
  375.                         at3.Visible = vis
  376.                         at3.Orientation = torso.Orientation + Vector3.new(90,0,-90)
  377.                         at3.Position = Vector3.new(.5,-1,0)
  378.                                
  379.                         local at3p2 = Instance.new("Attachment")
  380.                         at3p2.Parent = RLeg
  381.                         at3p2.Visible = vis
  382.                         at3p2.Orientation = RLeg.Orientation + Vector3.new(90,0,-90)
  383.                         at3p2.Position = Vector3.new(0,1,0)
  384.                        
  385.                         local bis3 = Instance.new("BallSocketConstraint")
  386.                         bis3.Parent = RLeg
  387.                         bis3.Attachment0 = at3
  388.                         bis3.Attachment1 = at3p2
  389.                         bis3.LimitsEnabled = true
  390.                         bis3.UpperAngle = 180-15
  391.                         bis3.Visible = vis2
  392.                         table.insert(js,1,bis3)
  393.                     end
  394.                          
  395.                     if LLeg and not LLeg:FindFirstChild('Dismembered') then  
  396.                         local at4 = Instance.new("Attachment")
  397.                         at4.Parent = torso
  398.                         at4.Visible = vis
  399.                         at4.Orientation = torso.Orientation + Vector3.new(90,0,-90)
  400.                         at4.Position = Vector3.new(-.5,-1,0)
  401.                                
  402.                         local at4p2 = Instance.new("Attachment")
  403.                         at4p2.Parent = LLeg
  404.                         at4p2.Visible = vis
  405.                         at4p2.Orientation = LLeg.Orientation + Vector3.new(90,0,-90)
  406.                         at4p2.Position = Vector3.new(0,1,0)
  407.                    
  408.                         local bis4 = Instance.new("BallSocketConstraint")
  409.                         bis4.Parent = LLeg
  410.                         bis4.Attachment0 = at4
  411.                         bis4.Attachment1 = at4p2
  412.                         bis4.LimitsEnabled = true
  413.                         bis4.UpperAngle = 180-15
  414.                         bis4.Visible = vis2
  415.                         table.insert(js,1,bis4)
  416.                     end
  417.                    
  418.                     if head and not headless and not head:FindFirstChild('Dismembered') then  
  419.                             local at5 = Instance.new("Attachment")
  420.                             at5.Parent = torso
  421.                             at5.Visible = vis
  422.                             at5.Orientation = torso.Orientation + Vector3.new(180,90,0)
  423.                             at5.Position = Vector3.new(0,1,0)
  424.                          
  425.                             local at5p2 = Instance.new("Attachment")
  426.                             at5p2.Parent = head
  427.                             at5p2.Visible = vis
  428.                             at5p2.Orientation = head.Orientation + Vector3.new(180,90,0)
  429.                             at5p2.Position = Vector3.new(0,-.5,0)
  430.                    
  431.                             local bis5 = Instance.new("BallSocketConstraint")
  432.                             bis5.Parent = head
  433.                             bis5.Attachment0 = at5p2
  434.                             bis5.Attachment1 = at5
  435.                             bis5.LimitsEnabled = true
  436.                             bis5.UpperAngle = 75
  437.                             bis5.Visible = vis2
  438.                             bis5.TwistLimitsEnabled = true
  439.                             bis5.UpperAngle = -45
  440.                             bis5.TwistLowerAngle = -45
  441.                             table.insert(js,1,bis5)
  442.                         else
  443.                             --head:BreakJoints()
  444.                         end
  445.                     end
  446.             else
  447.                 hum.Died:Connect(function()
  448.                 if hum.RigType==Enum.HumanoidRigType.R6 then
  449.                     for _,v in pairs(torso:GetDescendants()) do
  450.                         if (v:IsA('Motor6D') or v:IsA('Motor') or v:IsA('Weld') or v:IsA("BallSocketConstraint")) and (not string.match(v.Name:lower(),'root')) then
  451.                             if not kill then
  452.                                 table.insert(js2,1,{obj = v,par = v.Parent})
  453.                                 v.Parent = nil
  454.                             elseif kill then
  455.                                 v:Destroy()
  456.                             end
  457.                         end
  458.                     end
  459.                    local vis = false
  460.                    local vis2 = false
  461.                     if LArm and not LArm:FindFirstChild('Dismembered') then
  462.                        local at1 = Instance.new("Attachment")
  463.                        at1.Parent = torso
  464.                        at1.Visible = vis
  465.                        at1.Orientation = torso.Orientation + Vector3.new(0,180,0)
  466.                        at1.Position = Vector3.new(-1,1,0)
  467.                                        
  468.                        local at1p2 = Instance.new("Attachment")
  469.                        at1p2.Parent = LArm
  470.                        at1p2.Visible = vis
  471.                        at1p2.Orientation = LArm.Orientation + Vector3.new(0,180,0)
  472.                        at1p2.Position = Vector3.new(.5,1,0)
  473.                            
  474.                        local bis = Instance.new("BallSocketConstraint")
  475.                        bis.Parent = LArm
  476.                        bis.Attachment0 = at1
  477.                        bis.Attachment1 = at1p2
  478.                        bis.LimitsEnabled = true
  479.                        bis.UpperAngle = 15
  480.                        bis.Visible = vis2
  481.                        bis.TwistLimitsEnabled = true
  482.                        bis.UpperAngle = -45
  483.                        bis.TwistLowerAngle = -45
  484.                         table.insert(js,1,bis)
  485.                     end
  486.                     if RArm and not RArm:FindFirstChild('Dismembered') then    
  487.                         local at2 = Instance.new("Attachment")
  488.                         at2.Parent = torso
  489.                         at2.Visible = vis
  490.                         at2.Orientation = torso.Orientation + Vector3.new(0,0,0)
  491.                         at2.Position = Vector3.new(1,1,0)
  492.                                
  493.                         local at2p2 = Instance.new("Attachment")
  494.                         at2p2.Parent = RArm
  495.                         at2p2.Visible = vis
  496.                         at2p2.Orientation = RArm.Orientation + Vector3.new(0,0,0)
  497.                         at2p2.Position = Vector3.new(-.5,1,0)
  498.                        
  499.                         local bis2 = Instance.new("BallSocketConstraint")
  500.                         bis2.Parent = RArm
  501.                         bis2.Attachment0 = at2
  502.                         bis2.Attachment1 = at2p2
  503.                         bis2.LimitsEnabled = true
  504.                         bis2.UpperAngle = 15
  505.                         bis2.Visible = vis2
  506.                         bis2.TwistLimitsEnabled = true
  507.                         bis2.UpperAngle = -45
  508.                         bis2.TwistLowerAngle = -45
  509.                         table.insert(js,1,bis2)
  510.                     end
  511.                      if RLeg and not RLeg:FindFirstChild('Dismembered') then
  512.                         local at3 = Instance.new("Attachment")
  513.                         at3.Parent = torso
  514.                         at3.Visible = vis
  515.                         at3.Orientation = torso.Orientation + Vector3.new(90,0,-90)
  516.                         at3.Position = Vector3.new(.5,-1,0)
  517.                                
  518.                         local at3p2 = Instance.new("Attachment")
  519.                         at3p2.Parent = RLeg
  520.                         at3p2.Visible = vis
  521.                         at3p2.Orientation = RLeg.Orientation + Vector3.new(90,0,-90)
  522.                         at3p2.Position = Vector3.new(0,1,0)
  523.                        
  524.                         local bis3 = Instance.new("BallSocketConstraint")
  525.                         bis3.Parent = RLeg
  526.                         bis3.Attachment0 = at3
  527.                         bis3.Attachment1 = at3p2
  528.                         bis3.LimitsEnabled = true
  529.                         bis3.UpperAngle = 180-15
  530.                         bis3.Visible = vis2
  531.                         table.insert(js,1,bis3)
  532.                     end
  533.                          
  534.                     if LLeg and not LLeg:FindFirstChild('Dismembered') then  
  535.                         local at4 = Instance.new("Attachment")
  536.                         at4.Parent = torso
  537.                         at4.Visible = vis
  538.                         at4.Orientation = torso.Orientation + Vector3.new(90,0,-90)
  539.                         at4.Position = Vector3.new(-.5,-1,0)
  540.                                
  541.                         local at4p2 = Instance.new("Attachment")
  542.                         at4p2.Parent = LLeg
  543.                         at4p2.Visible = vis
  544.                         at4p2.Orientation = LLeg.Orientation + Vector3.new(90,0,-90)
  545.                         at4p2.Position = Vector3.new(0,1,0)
  546.                    
  547.                         local bis4 = Instance.new("BallSocketConstraint")
  548.                         bis4.Parent = LLeg
  549.                         bis4.Attachment0 = at4
  550.                         bis4.Attachment1 = at4p2
  551.                         bis4.LimitsEnabled = true
  552.                         bis4.UpperAngle = 180-15
  553.                         bis4.Visible = vis2
  554.                         table.insert(js,1,bis4)
  555.                     end
  556.                    
  557.                     if head and not headless and not head:FindFirstChild('Dismembered') then  
  558.                             local at5 = Instance.new("Attachment")
  559.                             at5.Parent = torso
  560.                             at5.Visible = vis
  561.                             at5.Orientation = torso.Orientation + Vector3.new(180,90,0)
  562.                             at5.Position = Vector3.new(0,1,0)
  563.                          
  564.                             local at5p2 = Instance.new("Attachment")
  565.                             at5p2.Parent = head
  566.                             at5p2.Visible = vis
  567.                             at5p2.Orientation = head.Orientation + Vector3.new(180,90,0)
  568.                             at5p2.Position = Vector3.new(0,-.5,0)
  569.                    
  570.                             local bis5 = Instance.new("BallSocketConstraint")
  571.                             bis5.Parent = head
  572.                             bis5.Attachment0 = at5p2
  573.                             bis5.Attachment1 = at5
  574.                             bis5.LimitsEnabled = true
  575.                             bis5.UpperAngle = 75
  576.                             bis5.Visible = vis2
  577.                             bis5.TwistLimitsEnabled = true
  578.                             bis5.UpperAngle = -45
  579.                             bis5.TwistLowerAngle = -45
  580.                             table.insert(js,1,bis5)
  581.                         else
  582.                             --head:BreakJoints()
  583.                         end
  584.                     end
  585.                 end)
  586.             end
  587.         elseif head and hum then
  588.             hum.BreakJointsOnDeath = false
  589.             if insta then
  590.                 if hum.RigType==Enum.HumanoidRigType.R15 then
  591.                     for _,v in pairs(pc:GetDescendants()) do
  592.                         if (v:IsA('Motor6D') or v:IsA('Motor') or v:IsA("BallSocketConstraint")) and (not string.match(v.Name:lower(),'root')) then
  593.                             if not kill then
  594.                                 table.insert(js2,1,{obj = v,par = v.Parent})
  595.                                 v.Parent = nil
  596.                             elseif kill then
  597.                                 v:Destroy()
  598.                             end
  599.                         end
  600.                     end
  601.                     local vis = false
  602.                     local vis2 = false
  603.                        
  604.                     if LF and not LF:FindFirstChild('Dismembered') then  
  605.                         local bsc1 = Instance.new("BallSocketConstraint",LF)
  606.                         bsc1.Attachment0 = LF.LeftAnkleRigAttachment
  607.                         bsc1.Attachment1 = LLL.LeftAnkleRigAttachment
  608.                         table.insert(js,1,bsc1)
  609.                     end
  610.                     if LLL and not LLL:FindFirstChild('Dismembered') then  
  611.                         local bsc2 = Instance.new("BallSocketConstraint",LLL)
  612.                         bsc2.Attachment0 = LLL.LeftKneeRigAttachment
  613.                         bsc2.Attachment1 = LUL.LeftKneeRigAttachment
  614.                         table.insert(js,1,bsc2)
  615.                     end
  616.                     if LUL and not LUL:FindFirstChild('Dismembered') then  
  617.                         local bsc3 = Instance.new("BallSocketConstraint",LUL)
  618.                         bsc3.Attachment0 = LUL.LeftHipRigAttachment
  619.                         bsc3.Attachment1 = LT.LeftHipRigAttachment
  620.                         table.insert(js,1,bsc3)
  621.                     end
  622.                     if RF and not RF:FindFirstChild('Dismembered') then  
  623.                         local bsc4 = Instance.new("BallSocketConstraint",RF)
  624.                         bsc4.Attachment0 = RF.RightAnkleRigAttachment
  625.                         bsc4.Attachment1 = RLL.RightAnkleRigAttachment
  626.                         table.insert(js,1,bsc4)
  627.                     end
  628.                     if RLL and not RLL:FindFirstChild('Dismembered') then  
  629.                         local bsc5 = Instance.new("BallSocketConstraint",RLL)
  630.                         bsc5.Attachment0 = RLL.RightKneeRigAttachment
  631.                         bsc5.Attachment1 = RUL.RightKneeRigAttachment
  632.                         table.insert(js,1,bsc5)
  633.                     end
  634.                     if RUL and not RUL:FindFirstChild('Dismembered') then  
  635.                         local bsc6 = Instance.new("BallSocketConstraint",RUL)
  636.                         bsc6.Attachment0 = RUL.RightHipRigAttachment
  637.                         bsc6.Attachment1 = LT.RightHipRigAttachment
  638.                         table.insert(js,1,bsc6)
  639.                     end
  640.                     if LH and not LH:FindFirstChild('Dismembered') then  
  641.                         local bsc7 = Instance.new("BallSocketConstraint",LH)
  642.                         bsc7.Attachment0 = LH.LeftWristRigAttachment
  643.                         bsc7.Attachment1 = LLA.LeftWristRigAttachment
  644.                         table.insert(js,1,bsc7)
  645.                     end
  646.                     if LLA and not LLA:FindFirstChild('Dismembered') then  
  647.                         local bsc8 = Instance.new("BallSocketConstraint",LLA)
  648.                         bsc8.Attachment0 = LLA.LeftElbowRigAttachment
  649.                         bsc8.Attachment1 = LUA.LeftElbowRigAttachment
  650.                         table.insert(js,1,bsc8)
  651.                     end
  652.                     if LUA and not LUA:FindFirstChild('Dismembered') then  
  653.                         local bsc9 = Instance.new("BallSocketConstraint",LUA)
  654.                         bsc9.Attachment0 = LUA.LeftShoulderAttachment
  655.                         bsc9.Attachment1 = UT.LeftCollarAttachment
  656.                         table.insert(js,1,bsc9)
  657.                     end
  658.                     if RH and not RH:FindFirstChild('Dismembered') then  
  659.                         local bsc10 = Instance.new("BallSocketConstraint",RH)
  660.                         bsc10.Attachment0 = RH.RightWristRigAttachment
  661.                         bsc10.Attachment1 = RLA.RightWristRigAttachment
  662.                         table.insert(js,1,bsc10)
  663.                     end
  664.                     if RLA and not RLA:FindFirstChild('Dismembered') then  
  665.                         local bsc11 = Instance.new("BallSocketConstraint",RLA)
  666.                         bsc11.Attachment0 = RLA.RightElbowRigAttachment
  667.                         bsc11.Attachment1 = RUA.RightElbowRigAttachment
  668.                         table.insert(js,1,bsc11)
  669.                     end
  670.                     if RUA and not RUA:FindFirstChild('Dismembered') then  
  671.                         local bsc12 = Instance.new("BallSocketConstraint",RUA)
  672.                         bsc12.Attachment0 = RUA.RightShoulderAttachment
  673.                         bsc12.Attachment1 = UT.RightCollarAttachment
  674.                         table.insert(js,1,bsc12)
  675.                     end
  676.                     if LT and not LT:FindFirstChild('Dismembered') then  
  677.                         local bsc13 = Instance.new("BallSocketConstraint",LT)
  678.                         bsc13.Attachment0 = LT.WaistRigAttachment
  679.                         bsc13.Attachment1 = UT.WaistRigAttachment
  680.                         table.insert(js,1,bsc13)
  681.                     end
  682.                     if head and not headless and not head:FindFirstChild('Dismembered')  then
  683.                         local bsc14 = Instance.new("BallSocketConstraint",head)
  684.                         bsc14.Attachment0 = UT.NeckRigAttachment
  685.                         bsc14.Attachment1 = head.NeckRigAttachment
  686.                         bsc14.LimitsEnabled = true
  687.                         bsc14.UpperAngle = -75
  688.                         bsc14.TwistLimitsEnabled = true
  689.                         bsc14.UpperAngle = -45
  690.                         bsc14.TwistLowerAngle = -45
  691.                         table.insert(js,1,bsc14)
  692.                     else
  693.                         --head:BreakJoints()
  694.                     end
  695.                 end
  696.             else
  697.                 hum.Died:Connect(function()
  698.                     if hum.RigType==Enum.HumanoidRigType.R15 then
  699.                         for _,v in pairs(pc:GetDescendants()) do
  700.                             if (v:IsA('Motor6D') or v:IsA('Motor') or v:IsA("BallSocketConstraint")) and (not string.match(v.Name:lower(),'root')) then
  701.                                 if not kill then
  702.                                     table.insert(js2,1,{obj = v,par = v.Parent})
  703.                                     v.Parent = nil
  704.                                 elseif kill then
  705.                                     v:Destroy()
  706.                                 end
  707.                             end
  708.                         end
  709.                         local vis = false
  710.                         local vis2 = false
  711.                            
  712.                         if LF and not LF:FindFirstChild('Dismembered') then  
  713.                             local bsc1 = Instance.new("BallSocketConstraint",LF)
  714.                             bsc1.Attachment0 = LF.LeftAnkleRigAttachment
  715.                             bsc1.Attachment1 = LLL.LeftAnkleRigAttachment
  716.                             table.insert(js,1,bsc1)
  717.                         end
  718.                         if LLL and not LLL:FindFirstChild('Dismembered') then  
  719.                             local bsc2 = Instance.new("BallSocketConstraint",LLL)
  720.                             bsc2.Attachment0 = LLL.LeftKneeRigAttachment
  721.                             bsc2.Attachment1 = LUL.LeftKneeRigAttachment
  722.                             table.insert(js,1,bsc2)
  723.                         end
  724.                         if LUL and not LUL:FindFirstChild('Dismembered') then  
  725.                             local bsc3 = Instance.new("BallSocketConstraint",LUL)
  726.                             bsc3.Attachment0 = LUL.LeftHipRigAttachment
  727.                             bsc3.Attachment1 = LT.LeftHipRigAttachment
  728.                             table.insert(js,1,bsc3)
  729.                         end
  730.                         if RF and not RF:FindFirstChild('Dismembered') then  
  731.                             local bsc4 = Instance.new("BallSocketConstraint",RF)
  732.                             bsc4.Attachment0 = RF.RightAnkleRigAttachment
  733.                             bsc4.Attachment1 = RLL.RightAnkleRigAttachment
  734.                             table.insert(js,1,bsc4)
  735.                         end
  736.                         if RLL and not RLL:FindFirstChild('Dismembered') then  
  737.                             local bsc5 = Instance.new("BallSocketConstraint",RLL)
  738.                             bsc5.Attachment0 = RLL.RightKneeRigAttachment
  739.                             bsc5.Attachment1 = RUL.RightKneeRigAttachment
  740.                             table.insert(js,1,bsc5)
  741.                         end
  742.                         if RUL and not RUL:FindFirstChild('Dismembered') then  
  743.                             local bsc6 = Instance.new("BallSocketConstraint",RUL)
  744.                             bsc6.Attachment0 = RUL.RightHipRigAttachment
  745.                             bsc6.Attachment1 = LT.RightHipRigAttachment
  746.                             table.insert(js,1,bsc6)
  747.                         end
  748.                         if LH and not LH:FindFirstChild('Dismembered') then  
  749.                             local bsc7 = Instance.new("BallSocketConstraint",LH)
  750.                             bsc7.Attachment0 = LH.LeftWristRigAttachment
  751.                             bsc7.Attachment1 = LLA.LeftWristRigAttachment
  752.                             table.insert(js,1,bsc7)
  753.                         end
  754.                         if LLA and not LLA:FindFirstChild('Dismembered') then  
  755.                             local bsc8 = Instance.new("BallSocketConstraint",LLA)
  756.                             bsc8.Attachment0 = LLA.LeftElbowRigAttachment
  757.                             bsc8.Attachment1 = LUA.LeftElbowRigAttachment
  758.                             table.insert(js,1,bsc8)
  759.                         end
  760.                         if LUA and not LUA:FindFirstChild('Dismembered') then  
  761.                             local bsc9 = Instance.new("BallSocketConstraint",LUA)
  762.                             bsc9.Attachment0 = LUA.LeftShoulderAttachment
  763.                             bsc9.Attachment1 = UT.LeftCollarAttachment
  764.                             table.insert(js,1,bsc9)
  765.                         end
  766.                         if RH and not RH:FindFirstChild('Dismembered') then  
  767.                             local bsc10 = Instance.new("BallSocketConstraint",RH)
  768.                             bsc10.Attachment0 = RH.RightWristRigAttachment
  769.                             bsc10.Attachment1 = RLA.RightWristRigAttachment
  770.                             table.insert(js,1,bsc10)
  771.                         end
  772.                         if RLA and not RLA:FindFirstChild('Dismembered') then  
  773.                             local bsc11 = Instance.new("BallSocketConstraint",RLA)
  774.                             bsc11.Attachment0 = RLA.RightElbowRigAttachment
  775.                             bsc11.Attachment1 = RUA.RightElbowRigAttachment
  776.                             table.insert(js,1,bsc11)
  777.                         end
  778.                         if RUA and not RUA:FindFirstChild('Dismembered') then  
  779.                             local bsc12 = Instance.new("BallSocketConstraint",RUA)
  780.                             bsc12.Attachment0 = RUA.RightShoulderAttachment
  781.                             bsc12.Attachment1 = UT.RightCollarAttachment
  782.                             table.insert(js,1,bsc12)
  783.                         end
  784.                         if LT and not LT:FindFirstChild('Dismembered') then  
  785.                             local bsc13 = Instance.new("BallSocketConstraint",LT)
  786.                             bsc13.Attachment0 = LT.WaistRigAttachment
  787.                             bsc13.Attachment1 = UT.WaistRigAttachment
  788.                             table.insert(js,1,bsc13)
  789.                         end
  790.                         if head and not headless and not head:FindFirstChild('Dismembered')  then
  791.                             local bsc14 = Instance.new("BallSocketConstraint",head)
  792.                             bsc14.Attachment0 = UT.NeckRigAttachment
  793.                             bsc14.Attachment1 = head.NeckRigAttachment
  794.                             bsc14.LimitsEnabled = true
  795.                             bsc14.UpperAngle = -75
  796.                             bsc14.TwistLimitsEnabled = true
  797.                             bsc14.UpperAngle = -45
  798.                             bsc14.TwistLowerAngle = -45
  799.                             table.insert(js,1,bsc14)
  800.                         else
  801.                             --head:BreakJoints()
  802.                         end
  803.                     end
  804.                 end)
  805.             end
  806.         end
  807.     end
  808.     return js,js2
  809. end
  810.  
  811. function hook(char)
  812.     if char then else return end
  813.     local hum = char:FindFirstChildOfClass("Humanoid")
  814.     hum.Died:Connect(function()
  815.         local tempkillval = Instance.new("ObjectValue")
  816.         tempkillval.Name = 'killer'
  817.         tempkillval.Value = nil -- plr
  818.         tempkillval.Parent = hum
  819.         hum:TakeDamage(1/0)
  820.         local ragval = Instance.new("ObjectValue")
  821.         ragval.Name = 'Ragdolled'
  822.         ragval.Parent = hum
  823.         hum.AutoRotate = false
  824.         hum.PlatformStand = true
  825.         Ragdoll(char,false,true,true)
  826.     end)
  827. end
  828.  
  829. for i,plr in pairs(game:GetService("Players"):GetPlayers()) do
  830.     hook(plr.Character)
  831.     plr.CharacterAdded:Connect(hook)
  832. end
  833.  
  834. game:GetService("Players").PlayerAdded:Connect(function(plr)
  835.     plr.CharacterAdded:Connect(hook)
  836. end)
Add Comment
Please, Sign In to add comment