Advertisement
KrYn0MoRe

ragdoll v2

Nov 25th, 2020 (edited)
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.21 KB | None | 0 0
  1. local junk = workspace:FindFirstChild('junk') or workspace
  2.  
  3. function limb_collide(obj,mode,d)
  4.     if (obj:IsA("UnionOperation") or obj:IsA("BasePart")) and not obj:FindFirstChild('limb') then else return end
  5.     local exists = pcall(game:GetService("PhysicsService").GetCollisionGroupId, game:GetService("PhysicsService"), 'Limb Collide')
  6.     if not exists then
  7.         game:GetService("PhysicsService"):CreateCollisionGroup('Limb Collide')
  8.     end
  9.     game:GetService("PhysicsService"):CollisionGroupSetCollidable('Limb Collide','Limb Collide',false)
  10.     --
  11.     local t = {}
  12.     --
  13.     local cb = Instance.new("Part")
  14.     cb.Name = 'limb'
  15.     cb.Transparency = 1
  16.     cb.CanCollide = true
  17.     cb.Anchored = false
  18.     cb.CFrame = obj.CFrame
  19.     cb.Size = obj.Size
  20.     cb.Massless = true
  21.     cb.Locked = true
  22.     game:GetService("PhysicsService"):SetPartCollisionGroup(cb,'Limb Collide')
  23.     game:GetService("PhysicsService"):SetPartCollisionGroup(obj,'Limb Collide')
  24.     local weld = Instance.new("Weld")
  25.     weld.Part0 = cb
  26.     weld.Part1 = obj
  27.     weld.Parent = cb
  28.     obj.Massless = true
  29.     obj.Anchored = false
  30.     if mode or obj:FindFirstChild("Dismembered") then
  31.         cb.Parent = junk -- .Parent
  32.     else
  33.         cb.Parent = junk
  34.         table.insert(t,1,cb)
  35.     end
  36.     if d then
  37.         game:GetService("Debris"):AddItem(cb,d)
  38.     end
  39.     --
  40.     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
  41.         local lv = Vector3.new() -- Vector3.new(cb.Size.X,0,cb.Size.Z)
  42.         local cb2 = Instance.new("Part")
  43.         cb2.Name = 'limb'
  44.         cb2.Transparency = 1
  45.         cb2.CanCollide = true
  46.         cb2.Anchored = false
  47.         cb2.CFrame = obj.CFrame
  48.         cb2.Size = lv
  49.         cb2.Massless = true
  50.         cb2.Locked = true
  51.         --game:GetService("PhysicsService"):SetPartCollisionGroup(cb2,'Limb Collide')
  52.         local weld2 = Instance.new("Weld")
  53.         weld2.Part0 = cb
  54.         weld2.Part1 = cb2
  55.         weld2.C1 = CFrame.new(0,(cb.Size.Y/2),0)
  56.         weld2.Parent = cb2
  57.         if mode or obj:FindFirstChild("Dismembered") then
  58.             cb2.Parent = junk -- .Parent
  59.         else
  60.             cb2.Parent = junk
  61.             table.insert(t,1,cb2)
  62.         end
  63.         if d then
  64.             game:GetService("Debris"):AddItem(cb2,d)
  65.         end
  66.     end
  67.     --
  68.     return t
  69. end
  70.  
  71. function ragdoll(targchar,kill,remove)
  72.     local targplr
  73.     pcall(function()
  74.         targplr = game:GetService("Players"):GetPlayerFromCharacter(targchar)
  75.     end)
  76.     local pc = targchar
  77.     local targhum = pc:FindFirstChild("Humanoid")
  78.     local js,js2 = {},{}
  79.    
  80.     if kill then
  81.         local old_pc
  82.         if remove then
  83.             pc.Archivable = true
  84.             old_pc = pc
  85.             pc = pc:Clone()
  86.         end
  87.         for i,v in pairs(pc:GetDescendants()) do
  88.             if v.Name ~= 'HumanoidRootPart' and v.Name ~= 'Torso' and v:IsA("BasePart") then
  89.                 if remove then
  90.                     limb_collide(v,true,10)
  91.                 end
  92.             end
  93.             if v:IsA("ParticleEmitter") then
  94.                 v.Enabled = false
  95.             end
  96.             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
  97.                 if v:IsA("BodyVelocity") then
  98.                     game:GetService("Debris"):AddItem(v,0.15)
  99.                 else
  100.                     v:Destroy()
  101.                 end
  102.             end
  103.             if (v:IsA("Script") and v.Name == 'Health') or (v:IsA("LocalScript") and v.Name == 'Animate') then
  104.                 v:Destroy()
  105.             end
  106.             if v:IsA("Humanoid") then
  107.                 v.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
  108.                 v.PlatformStand = true
  109.             end
  110.         end
  111.         if remove then
  112.             for i,v in pairs(old_pc:GetDescendants()) do
  113.                 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
  114.                     v:destroy()
  115.                 end
  116.                 if v:IsA("Humanoid") then
  117.                     v.BreakJointsOnDeath = true
  118.                     v.Health = 0
  119.                     v.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
  120.                     v.PlatformStand = true
  121.                 end
  122.             end
  123.             pc.Parent = junk
  124.             game:GetService("Debris"):AddItem(pc,10)
  125.         end
  126.     end
  127.     if kill and targhum:FindFirstChild("Ragdolled") then return; end;
  128.     coroutine.resume(coroutine.create(function()
  129.         if targplr then
  130.             for i,v in pairs(pc:GetChildren()) do
  131.                 if v:IsA("BasePart") then
  132.                     --v.Massless = true
  133.                     if v:CanSetNetworkOwnership() then
  134.                         v:SetNetworkOwner(targplr)
  135.                     end
  136.                 end
  137.             end
  138.         end
  139.     end))
  140.     local kb = 15
  141.     local targtorso = pc:FindFirstChild("Torso") or pc:FindFirstChild("UpperTorso") or pc:FindFirstChild("Head") or pc:FindFirstChild("HumanoidRootPart")
  142.     local dir = targtorso.CFrame.lookVector*-1
  143.     local bv = Instance.new("BodyVelocity")
  144.     bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
  145.     bv.Velocity = --[[dir*kb+]]Vector3.new(0,kb,0)
  146.     bv.Parent = targtorso
  147.     game:GetService("Debris"):AddItem(bv,0.1)
  148.     local ragval = Instance.new("ObjectValue")
  149.     ragval.Name = 'Ragdolled'
  150.     ragval.Parent = targhum
  151.     spawn(function()
  152.         for _,m in pairs(pc:GetChildren()) do
  153.             for _,v in pairs(m:GetChildren()) do
  154.                 if v:IsA("Snap") or v:IsA('Weld') then
  155.                     v:Destroy()
  156.                 end
  157.                 if (v:IsA('Motor6D') or v:IsA('Motor')) and v.Parent:IsA("Part") then
  158.                     if not kill then
  159.                         table.insert(js2,1,{obj = v,par = v.Parent})
  160.                     end
  161.  
  162.                     local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
  163.                     a0.CFrame = v.C0
  164.                     a1.CFrame = v.C1
  165.                     a0.Parent = v.Part0
  166.                     a1.Parent = v.Part1
  167.  
  168.                     local b = Instance.new("BallSocketConstraint")
  169.                     b.Attachment0 = a0
  170.                     b.Attachment1 = a1
  171.                     b.Parent = v.Part0
  172.  
  173.                     v.Parent = nil
  174.                     table.insert(js,1,b)
  175.                 end
  176.             end
  177.         end
  178.     end)
  179.     pcall(function()
  180.         pc.HumanoidRootPart.CanCollide = false
  181.     end)
  182.     return js,js2
  183. end
  184.  
  185. function hook(char)
  186.     if char then else return end
  187.     repeat wait() until char:FindFirstChildOfClass("Humanoid")
  188.     local hum = char:FindFirstChildOfClass("Humanoid")
  189.     hum.BreakJointsOnDeath = false
  190.     hum.Died:Connect(function()
  191.         hum.BreakJointsOnDeath = false
  192.         local tempkillval = Instance.new("ObjectValue")
  193.         tempkillval.Name = 'killer'
  194.         tempkillval.Value = nil -- plr
  195.         tempkillval.Parent = hum
  196.         hum:TakeDamage(1/0)
  197.         pcall(function()
  198.             ragdoll(char,true)
  199.         end)
  200.     end)
  201. end
  202.  
  203. for i,plr in pairs(game:GetService("Players"):GetPlayers()) do
  204.     hook(plr.Character)
  205.     plr.CharacterAdded:Connect(hook)
  206. end
  207.  
  208. game:GetService("Players").PlayerAdded:Connect(function(plr)
  209.     plr.CharacterAdded:Connect(hook)
  210. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement