DrawingJhon

Ragdoll????

Oct 10th, 2021 (edited)
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.63 KB | None | 0 0
  1. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  2. local Workspace = game:GetService("Workspace")
  3. local Debris = game:GetService("Debris")
  4. local RagdollState = (ReplicatedStorage:WaitForChild("Events")):WaitForChild("RagdollState")
  5. local LocalRagdollEvent = ReplicatedStorage:WaitForChild("LocalRagdollEvent")
  6. local Delay = ReplicatedStorage:WaitForChild("Delay")
  7. local Player = game:GetService("Players").LocalPlayer
  8. local Character = Player.Character
  9.  
  10. if not Character then
  11.     Character = Player.CharacterAdded
  12.     local NewCharacter = Player.CharacterAdded:Wait()
  13. end
  14.  
  15. local Humanoid = NewCharacter:WaitForChild("Humanoid")
  16. local HumanoidRootPart = NewCharacter:WaitForChild("HumanoidRootPart")
  17. local Motors = ((ReplicatedStorage:WaitForChild("PlayerInfo")):WaitForChild(NewCharacter.Name)):WaitForChild("Motors")
  18.  
  19. LocalRagdollEvent.Event:Connect(function(p1)
  20.     local Humanoid_State = Humanoid:GetState()
  21.     if p1 then
  22.         if Humanoid_State ~= Enum.HumanoidStateType.Physics then
  23.             RagdollState:FireServer(true)
  24.             Delay.Value = Delay.Value + 3
  25.             Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
  26.             HumanoidRootPart.CanCollide = false
  27.             for i, children in pairs(NewCharacter:GetChildren()) do
  28.                 if children:IsA("BasePart") then
  29.                     for _, motor in pairs(children:GetChildren()) do
  30.                         if motor:IsA("Motor6D") then
  31.                             motor.Parent = Motors
  32.                         end
  33.                     end
  34.                 end
  35.             end
  36.         elseif Humanoid_State == Enum.HumanoidStateType.Physics then
  37.                 RagdollState:FireServer(false)
  38.                 Delay.Value = Delay.Value + 3
  39.                 local function returnMotor_1(name, parent)
  40.                     local found = Motors:FindFirstChild(name)
  41.                     if found and parent then
  42.                         found.Parent = parent
  43.                     end
  44.                 end
  45.                 if Humanoid.RigType == Enum.HumanoidRigType.R15 then
  46.                     returnMotor_1("Neck", NewCharacter:FindFirstChild("Head"))
  47.                     returnMotor_1("Waist", NewCharacter:FindFirstChild("UpperTorso"))
  48.                     returnMotor_1("Root", NewCharacter:FindFirstChild("LowerTorso"))
  49.                     returnMotor_1("LeftShoulder", NewCharacter:FindFirstChild("LeftUpperArm"))
  50.                     returnMotor_1("LeftElbow", NewCharacter:FindFirstChild("LeftLowerArm"))
  51.                     returnMotor_1("LeftWrist", NewCharacter:FindFirstChild("LeftHand"))
  52.                     returnMotor_1("RightShoulder", NewCharacter:FindFirstChild("RightUpperArm"))
  53.                     returnMotor_1("RightElbow", NewCharacter:FindFirstChild("RightLowerArm"))
  54.                     returnMotor_1("RightWrist", NewCharacter:FindFirstChild("RightHand"))
  55.                     returnMotor_1("LeftHip", NewCharacter:FindFirstChild("LeftUpperLeg"))
  56.                     returnMotor_1("LeftKnee", NewCharacter:FindFirstChild("LeftLowerLeg"))
  57.                     returnMotor_1("LeftAnkle", NewCharacter:FindFirstChild("LeftFoot"))
  58.                     returnMotor_1("RightHip", NewCharacter:FindFirstChild("RightUpperLeg"))
  59.                     returnMotor_1("RightKnee", NewCharacter:FindFirstChild("RightLowerLeg"))
  60.                     returnMotor_1("RightAnkle", NewCharacter:FindFirstChild("RightFoot"))
  61.                 else
  62.                     returnMotor_1("Neck", NewCharacter:FindFirstChild("Torso"))
  63.                     returnMotor_1("RootJoint", NewCharacter:FindFirstChild("HumanoidRootPart"))
  64.                     returnMotor_1("Left Shoulder", NewCharacter:FindFirstChild("Torso"))
  65.                     returnMotor_1("Right Shoulder", NewCharacter:FindFirstChild("Torso"))
  66.                     returnMotor_1("Left Hip", NewCharacter:FindFirstChild("Torso"))
  67.                     returnMotor_1("Right Hip", NewCharacter:FindFirstChild("Torso"))
  68.                 end
  69.                 HumanoidRootPart.CanCollide = true
  70.                 Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
  71.             end
  72.         end
  73.         return
  74.     end
  75. end)
  76. RagdollState.OnClientEvent:Connect(function(p5, p6, p7)
  77.     local stateType = Humanoid:GetState()
  78.     if stateType ~= Enum.HumanoidStateType.Physics then
  79.         if stateType ~= Enum.HumanoidStateType.Dead then
  80.             LocalRagdollEvent:Fire(true)
  81.         end
  82.     end
  83.     local mass = (function(char)
  84.         local num = 0
  85.         for i, v in pairs(char:GetChildren()) do
  86.             if v:IsA("BasePart") then
  87.                 num = num + v:GetMass()
  88.             elseif v:IsA("Accoutrement") then
  89.                  local handle = v:FindFirstChildOfClass("BasePart")
  90.                  if handle then
  91.                      num = num + handle:GetMass()
  92.                   end
  93.               end
  94.         end
  95.         return num
  96.     end)(NewCharacter)
  97.     if p5 then
  98.         if type(p5) == "userdata" then
  99.             local bodyForce = Instance.new("BodyForce")
  100.             bodyForce.Force = p5 * mass
  101.             bodyForce.Parent = HumanoidRootPart
  102.             Debris:AddItem(bodyForce, 0.1)
  103.         end
  104.     end
  105.     if p6 then
  106.         if type(p6) == "userdata" then
  107.             local bodyAngular = Instance.new("BodyAngularVelocity")
  108.             bodyAngular.AngularVelocity = p6 * mass
  109.             bodyAngular.Parent = HumanoidRootPart
  110.             Debris:AddItem(bodyAngular, 0.1)
  111.         end
  112.     end
  113.     kk = nil
  114.     if p7 then
  115.         if tonumber(p7) then
  116.             kk = p7
  117.         else
  118.             kk = 0
  119.         end
  120.         Delay.Value = Delay.Value + kk - 3
  121.         return
  122.     end
  123. end)
  124.  
Add Comment
Please, Sign In to add comment