CCCPaste

Ragdoll System

local Players = game:GetService("Players")

local function PlayerCharacterAdded(Character: Model)
	local Humanoid: Humanoid = Character:FindFirstChild("Humanoid")
	if not Humanoid then return end

	Humanoid.BreakJointsOnDeath = false

	Humanoid.Died:Connect(function()
		local Joints = {}

		for _, Descendant in Character:GetDescendants() do
			if Descendant:IsA("Motor6D") then
				table.insert(Joints, Descendant)
			end
		end

		for _, Joint in ipairs(Joints) do
			local Attachment0 = Instance.new("Attachment", Joint.Part0)
			local Attachment1 = Instance.new("Attachment", Joint.Part1)

			Attachment0.CFrame = Joint.C0
			Attachment1.CFrame = Joint.C1

			local BallSocket = Instance.new("BallSocketConstraint")
			BallSocket.Attachment0 = Attachment0
			BallSocket.Attachment1 = Attachment1
			BallSocket.Parent = Joint.Part0

			Joint:Destroy()
		end

		local Root = Character:FindFirstChild("HumanoidRootPart")
		if Root then
			Root.CanCollide = false
		end
	end)
end

Players.PlayerAdded:Connect(function(Player: Player)
	Player.CharacterAdded:Connect(function(Character: Model)
		PlayerCharacterAdded(Character)
	end)
end)