Advertisement
Guest User

Ragdoll Module from my game

a guest
Oct 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.13 KB | None | 0 0
  1. --ChuckXZ
  2.  
  3. local xz_Inst = Instance.new
  4. local xz_CF = CFrame.new
  5.  
  6. local Util = require(script.Parent.UtilityFunctions)
  7.  
  8. local ConstraintList = {
  9.    
  10.     --[[{
  11.         Name = "HumanoidRootPart",
  12.         Connector = "UpperTorso",
  13.         V1 = Vector3.new(0,0,1),
  14.         V2 = Vector3.new(0,0,-1)
  15.     },]]
  16.    
  17.     {
  18.         Name = "Head",
  19.         Connector = "UpperTorso",
  20.         V1 = Vector3.new(0,-.5,0),
  21.         V2 = Vector3.new(0,1,0)
  22.     },
  23.    
  24.     {
  25.         Name = "UpperTorso",
  26.         Connector = "LowerTorso",
  27.         V1 = Vector3.new(0,-.75,0),
  28.         V2 = Vector3.new(0,.25,0)
  29.     },
  30.    
  31.     {
  32.         Name = "LeftUpperArm",
  33.         Connector = "UpperTorso",
  34.         V1 = Vector3.new(.5,0,0),
  35.         V2 = Vector3.new(-1,.5,0),
  36.         HB = true
  37.     },
  38.    
  39.     {
  40.         Name = "LeftLowerArm",
  41.         Connector = "LeftUpperArm",
  42.         V1 = Vector3.new(0,0,0),
  43.         V2 = Vector3.new(0,-.5,0)
  44.     },
  45.    
  46.     {
  47.         Name = "LeftHand",
  48.         Connector = "LeftLowerArm",
  49.         V1 = Vector3.new(0,-.5,0),
  50.         V2 = Vector3.new(0,.1,0),
  51.         HB = true
  52.     },
  53.    
  54.     {
  55.         Name = "RightUpperArm",
  56.         Connector = "UpperTorso",
  57.         V1 = Vector3.new(.5,0,0),
  58.         V2 = Vector3.new(1,.5,0),
  59.         HB = true
  60.     },
  61.    
  62.     {
  63.         Name = "RightLowerArm",
  64.         Connector = "RightUpperArm",
  65.         V1 = Vector3.new(0,0,0),
  66.         V2 = Vector3.new(0,-.5,0)
  67.     },
  68.    
  69.     {
  70.         Name = "RightHand",
  71.         Connector = "RightLowerArm",
  72.         V1 = Vector3.new(0,-.5,0),
  73.         V2 = Vector3.new(0,.1,0),
  74.         HB = true
  75.     },
  76.    
  77.     {
  78.         Name = "LeftUpperLeg",
  79.         Connector = "LowerTorso",
  80.         V1 = Vector3.new(0,.5,0),
  81.         V2 = Vector3.new(-.8,-.1,0),
  82.         HB = true
  83.     },
  84.    
  85.     {
  86.         Name = "LeftLowerLeg",
  87.         Connector = "LeftUpperLeg",
  88.         V1 = Vector3.new(0,0,0),
  89.         V2 = Vector3.new(0,-.5,0)
  90.     },
  91.    
  92.     {
  93.         Name = "LeftFoot",
  94.         Connector = "LeftLowerLeg",
  95.         V1 = Vector3.new(0,-.5,0),
  96.         V2 = Vector3.new(0,.1,0),
  97.         HB = true
  98.     },
  99.    
  100.     {
  101.         Name = "RightUpperLeg",
  102.         Connector = "LowerTorso",
  103.         V1 = Vector3.new(0,.5,0),
  104.         V2 = Vector3.new(.8,-.1,0),
  105.         HB = true
  106.     },
  107.    
  108.     {
  109.         Name = "RightLowerLeg",
  110.         Connector = "RightUpperLeg",
  111.         V1 = Vector3.new(0,0,0),
  112.         V2 = Vector3.new(0,-.5,0)
  113.     },
  114.    
  115.     {
  116.         Name = "RightFoot",
  117.         Connector = "RightLowerLeg",
  118.         V1 = Vector3.new(0,-.5,0),
  119.         V2 = Vector3.new(0,.1,0),
  120.         HB = true
  121.     },
  122.    
  123. }
  124.  
  125. local MotorList = {
  126.    
  127.     {
  128.         Name = "Neck",
  129.         P1 = "UpperTorso",
  130.         P2 = "Head",
  131.         C0 = CFrame.new(-5.96046448e-08, 0.800017118, 1.1920929e-07, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  132.         C1 = CFrame.new(-0, -0.500000119, -0.000272244215, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  133.         Parent = "Head"
  134.     },
  135.    
  136.     {
  137.         Name = "Waist",
  138.         P1 = "LowerTorso",
  139.         P2 = "UpperTorso",
  140.         C0 = CFrame.new(-1.1920929e-07, 0.200024918, 7.64462551e-20, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  141.         C1 = CFrame.new(-5.96046448e-08, -0.799985707, 1.1920929e-07, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  142.         Parent = "UpperTorso"
  143.     },
  144.    
  145.     {
  146.         Name = "Root",
  147.         P1 = "HumanoidRootPart",
  148.         P2 = "LowerTorso",
  149.         C0 = CFrame.new(0, -0.349999994, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  150.         C1 = CFrame.new(-1.1920929e-07, -0.199972257, -0, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  151.         Parent = "LowerTorso"
  152.     },
  153.    
  154.     {
  155.         Name = "LeftHip",
  156.         P1 = "LowerTorso",
  157.         P2 = "LeftUpperLeg",
  158.         C0 = CFrame.new(-0.500000119, -0.199972257, -0, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  159.         C1 = CFrame.new(5.96046448e-08, 0.420782149, -1.63912773e-07, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  160.         Parent = "LeftUpperLeg"
  161.     },
  162.    
  163.     {
  164.         Name = "LeftKnee",
  165.         P1 = "LeftUpperLeg",
  166.         P2 = "LeftLowerLeg",
  167.         C0 = CFrame.new(8.94069672e-08, -0.401102364, -4.29081496e-07, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  168.         C1 = CFrame.new(2.98023224e-08, 0.379018426, -1.60860594e-07, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  169.         Parent = "LeftLowerLeg"
  170.     },
  171.    
  172.     {
  173.         Name = "LeftAnkle",
  174.         P1 = "LeftLowerLeg",
  175.         P2 = "LeftFoot",
  176.         C0 = CFrame.new(-1.1920929e-07, -0.547157168, -2.21401592e-06, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  177.         C1 = CFrame.new(-1.78813934e-07, 0.101939678, -1.7222776e-06, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  178.         Parent = "LeftFoot"
  179.     },
  180.    
  181.     {
  182.         Name = "RightHip",
  183.         P1 = "LowerTorso",
  184.         P2 = "RightUpperLeg",
  185.         C0 = CFrame.new(0.499999881, -0.199972257, -1.91208565e-05, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  186.         C1 = CFrame.new(-0, 0.420782268, -6.67300628e-05, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  187.         Parent = "RightUpperLeg"
  188.     },
  189.    
  190.     {
  191.         Name = "RightKnee",
  192.         P1 = "RightUpperLeg",
  193.         P2 = "RightLowerLeg",
  194.         C0 = CFrame.new(-0, -0.400946498, -2.18767891e-05, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  195.         C1 = CFrame.new(-0, 0.379174292, 2.5553607e-05, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  196.         Parent = "RightLowerLeg"
  197.     },
  198.    
  199.     {
  200.         Name = "RightAnkle",
  201.         P1 = "RightLowerLeg",
  202.         P2 = "RightFoot",
  203.         C0 = CFrame.new(-0, -0.547157168, 7.62689815e-05, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  204.         C1 = CFrame.new(-0, 0.101939559, 7.64477954e-05, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  205.         Parent = "RightFoot"
  206.     },
  207.    
  208.     {
  209.         Name = "LeftShoulder",
  210.         P1 = "UpperTorso",
  211.         P2 = "LeftUpperArm",
  212.         C0 = CFrame.new(-1, 0.56301713, 1.1920929e-07, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  213.         C1 = CFrame.new(0.500000358, 0.394326687, 8.94069672e-08, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  214.         Parent = "LeftUpperArm"
  215.     },
  216.    
  217.     {
  218.         Name = "LeftElbow",
  219.         P1 = "LeftUpperArm",
  220.         P2 = "LeftLowerArm",
  221.         C0 = CFrame.new(0.000479221344, -0.334056377, 8.94069672e-08, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  222.         C1 = CFrame.new(0.000478625298, 0.258688211, 7.64462551e-20, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  223.         Parent = "LeftLowerArm"
  224.     },
  225.    
  226.     {
  227.         Name = "LeftWrist",
  228.         P1 = "LeftLowerArm",
  229.         P2 = "LeftHand",
  230.         C0 = CFrame.new(0.000478625298, -0.5009287, 7.64462551e-20, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  231.         C1 = CFrame.new(0.000478982925, 0.125045404, 5.96046448e-08, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  232.         Parent = "LeftHand"
  233.     },
  234.    
  235.     {
  236.         Name = "RightShoulder",
  237.         P1 = "UpperTorso",
  238.         P2 = "RightUpperArm",
  239.         C0 = CFrame.new(0.99999994, 0.56301713, 1.1920929e-07, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  240.         C1 = CFrame.new(-0.500000715, 0.394326687, 8.94069672e-08, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  241.         Parent = "RightUpperArm"
  242.     },
  243.    
  244.     {
  245.         Name = "RightElbow",
  246.         P1 = "RightUpperArm",
  247.         P2 = "RightLowerArm",
  248.         C0 = CFrame.new(-5.96046448e-07, -0.334165096, 8.94069672e-08, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  249.         C1 = CFrame.new(1.1920929e-07, 0.258579493, 7.64462551e-20, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  250.         Parent = "RightLowerArm"
  251.     },
  252.    
  253.     {
  254.         Name = "RightWrist",
  255.         P1 = "RightLowerArm",
  256.         P2 = "RightHand",
  257.         C0 = CFrame.new(1.1920929e-07, -0.5009287, -6.86244753e-18, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  258.         C1 = CFrame.new(3.57627869e-07, 0.125045404, 5.96046448e-08, 1, 0, 0, 0, 1, 0, 0, 0, 1),
  259.         Parent = "RightHand"
  260.     },
  261.    
  262. }
  263.  
  264. local ConstList = {
  265.    
  266.     {
  267.         Type = "HingeConstraint",
  268.         Att1Off = Vector3.new()
  269.     }
  270.    
  271. }
  272.  
  273. local function MakeAttachment(Part,Pos)
  274.     local Att = xz_Inst("Attachment",Part)
  275.     Att.CFrame = xz_CF(Pos)
  276.     Att.Visible = true
  277.     return Att
  278. end
  279.  
  280. local function MakeConstraint(Att1, Att2)
  281.     local Constrnt = xz_Inst("RodConstraint",Att1.Parent)
  282.     Constrnt.Length = .25
  283.     Constrnt.Attachment0 = Att1
  284.     Constrnt.Attachment1 = Att2
  285.     Constrnt.Visible = true
  286. end
  287.  
  288. local function Weld(P0,P1,C0,C1,Id,Returned)
  289.     local W = Instance.new("Weld")
  290.     W.Name = Id
  291.     W.Parent = P1
  292.     W.Part0 = P0
  293.     W.Part1 = P1
  294.     W.C0 = C0
  295.     W.C1 = C1
  296.     if Returned then return W end
  297. end
  298.  
  299. local function HitBox(Prt)
  300.     local p = xz_Inst("Part")
  301.     p.Name = "Hitbox_" .. Prt.Name
  302.     p.Size = Prt.Size * .4
  303.     p.Anchored = false
  304.     p.CanCollide = true
  305.     p.Transparency = 1
  306.     p.Parent = Prt.Parent
  307.     Weld(Prt,p,xz_CF(0,0,0),xz_CF(0,0,0),"HB",false)
  308. end
  309.  
  310. local module = {}
  311.  
  312. function module:MakeRagDoll(char)
  313.     local model = xz_Inst("Model",game.Workspace.Debribs)
  314.     local cf
  315.     local t
  316.    
  317.     local Roog = xz_Inst("IntValue")
  318.     Roog.Name = "ragdoll"
  319.     Roog.Parent = char
  320.    
  321.     for i,v in pairs(game.ServerStorage.Dummy:GetDescendants()) do
  322.         if v:IsA("HingeConstraint") or v:IsA("BallSocketConstraint") then
  323.             spawn(function()
  324.                
  325.                 local cl = v:Clone()
  326.                 local at0 = cl.Attachment0:Clone()
  327.                 local at1 = cl.Attachment1:Clone()
  328.                 local atpar = cl.Attachment1.Parent.Name
  329.                 local parName = v.Parent.Name
  330.                
  331.                 local par1,par2 = char:FindFirstChild(atpar),char:FindFirstChild(parName)
  332.                 if par1 and par2 then
  333.                    
  334.                     cl.Parent = par2
  335.                     at0.Parent = par2
  336.                     at1.Parent = par1
  337.                     cl.Attachment0 = at0
  338.                     cl.Attachment1 = at1
  339.                    
  340.                     cl.Visible = false
  341.                     at0.Visible = false
  342.                     at1.Visible = false
  343.                    
  344.                 end
  345.                
  346.             end)
  347.         elseif v.Name == "HBW" then
  348.             local p1 = v.Part1.Name
  349.             local parr = char:FindFirstChild(p1)
  350.             if parr then
  351.                
  352.                 local cl = v.Part0:Clone()
  353.                 local mot = xz_Inst("Motor6D")
  354.                 mot.Name = "HBW"
  355.                 mot.Parent = cl
  356.                 cl.Parent = char
  357.                 mot.Part0 = cl
  358.                 mot.Part1 = parr
  359.                 mot.C0 = v.C0
  360.                 mot.C1 = v.C1
  361.                
  362.                 cl.Transparency = 1
  363.                
  364.             end
  365.         end
  366.     end
  367.    
  368.     for a,b in pairs(char:GetDescendants()) do
  369.         if b:IsA("JointInstance") and b.Name ~= "HBW" and b.Parent.Name ~= "Gun" and b.Name ~= "Neck" and not string.find(b.Parent.Name,"Hitbox_") and not b.Parent.Parent:IsA("Accessory") and not b:IsA("Accessory") then
  370.             b:Destroy()
  371.         end
  372.     end
  373.    
  374.     Weld(char.UpperTorso,char.HumanoidRootPart,CFrame.new(0,0,0),CFrame.new(0,0,0),"RootWeld",false)
  375.    
  376.     --model.PrimaryPart = t
  377.     --model:SetPrimaryPartCFrame(cf)
  378.    
  379.     --Collides(model)
  380. end
  381.  
  382. function module:FixRagdoll(char)
  383.    
  384.     local roge = char:FindFirstChild("ragdoll")
  385.     if roge then
  386.         roge:Destroy()
  387.     else
  388.         return
  389.     end
  390.    
  391.     for a,b in pairs(char:GetDescendants()) do
  392.         if b:IsA("BallSocketConstraint") or b:IsA("HingeConstraint") then
  393.             b.Attachment0:Destroy()
  394.             b.Attachment1:Destroy()
  395.             b:Destroy()
  396.         elseif b.Name == "HBW" then
  397.             b.Part0:Destroy()
  398.         end
  399.     end
  400.    
  401.     for i,v in pairs(MotorList) do
  402.        
  403.         local P1 = char:FindFirstChild(MotorList[i]["P1"])
  404.         local P2 = char:FindFirstChild(MotorList[i]["P2"])
  405.         local Par = char:FindFirstChild(MotorList[i]["Parent"])
  406.        
  407.         if P1 and P2 and Par then
  408.             local Mot = xz_Inst("Motor6D")
  409.             Mot.Name = MotorList[i]["Name"]
  410.             Mot.Parent = Par
  411.             Mot.Part0 = P1
  412.             Mot.Part1 = P2
  413.             Mot.C0 = MotorList[i]["C0"]
  414.             Mot.C1 = MotorList[i]["C1"]
  415.         end
  416.        
  417.     end
  418.    
  419.     local upp = char:FindFirstChild("HumanoidRootPart")
  420.     if upp then
  421.         local weldd = upp:FindFirstChild("RootWeld")
  422.         if weldd then
  423.             weldd:Destroy()
  424.         end
  425.         upp.CFrame = CFrame.new(upp.Position) + Vector3.new(0,3,0)
  426.     end
  427.    
  428.     local hum = char:FindFirstChild("Humanoid")
  429.     if hum then
  430.         hum:SetStateEnabled(Enum.HumanoidStateType.RunningNoPhysics,true)
  431.     end
  432.    
  433. end
  434.  
  435. return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement