Advertisement
Cakey3101

Ragdoll System

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