Advertisement
Cakey3101

Ragdoll System

Jun 12th, 2025 (edited)
759
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.36 KB | Source Code | 1 0
  1. local Players = game:GetService("Players")
  2.  
  3. local function CreateAttachmentsAndConstraint(Joint)
  4.     local Attachment0 = Instance.new("Attachment", Joint.Part0)
  5.     local Attachment1 = Instance.new("Attachment", Joint.Part1)
  6.  
  7.     Attachment0.CFrame = Joint.C0
  8.     Attachment1.CFrame = Joint.C1
  9.  
  10.     local BallSocket = Instance.new("BallSocketConstraint")
  11.     BallSocket.Attachment0 = Attachment0
  12.     BallSocket.Attachment1 = Attachment1
  13.     BallSocket.Parent = Joint.Part0
  14. end
  15.  
  16. local function HandleDeath(Character)
  17.     local Joints = {}
  18.  
  19.     for _, Descendant in Character:GetDescendants() do
  20.         if Descendant:IsA("Motor6D") then
  21.             table.insert(Joints, Descendant)
  22.         end
  23.     end
  24.  
  25.     for _, Joint in ipairs(Joints) do
  26.         CreateAttachmentsAndConstraint(Joint)
  27.         Joint:Destroy()
  28.     end
  29.  
  30.     local Root = Character:FindFirstChild("HumanoidRootPart")
  31.     if Root then
  32.         Root.CanCollide = false
  33.     end
  34. end
  35.  
  36. local function OnCharacterAdded(Character)
  37.     local Humanoid = Character:FindFirstChild("Humanoid")
  38.     if not Humanoid then return end
  39.  
  40.     Humanoid.BreakJointsOnDeath = false
  41.     Humanoid.Died:Connect(function()
  42.         HandleDeath(Character)
  43.     end)
  44. end
  45.  
  46. local function OnPlayerAdded(Player)
  47.     Player.CharacterAdded:Connect(OnCharacterAdded)
  48. end
  49.  
  50. Players.PlayerAdded:Connect(OnPlayerAdded)
Tags: robloxstudio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement