Ragdoll R6 method

I tried to ticker with the R15 script to create a ragdoll for R6 but unfortunately, R6 attachments are not made the same way like R15 where it can easily be referenced with some concatenation so it is difficult to make it work. There are just many differently named attachments.

Here’s what I tried:

game.Players.PlayerAdded:Connect(function(player) -- ragdoll implementation
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		humanoid.BreakJointsOnDeath = false
		local died
		died = humanoid.Died:Connect(function()
			local d = character:GetDescendants()
			for i=1,#d do
				local desc = d[i]
				if desc:IsA("Motor6D") then
					local socket = Instance.new("BallSocketConstraint")
					local part0 = desc.Part0
					local joint_name = desc.Name
					local attachment0 = desc.Part1:FindFirstChild("LeftShoulderAttachment") or desc.Part1:FindFirstChild("RightShoulderAttachment") or desc.Part1:FindFirstChildOfClass("Attachment")
					--local attachment0 = desc.Parent:FindFirstChild(joint_name.."Attachment") or desc.Parent:FindFirstChild(joint_name.."RigAttachment") -- original line of code for attachment0
					local attachment1 = part0:FindFirstChild(joint_name.."Attachment") or part0:FindFirstChild(joint_name.."RigAttachment")
					if attachment0 and attachment1 then
						socket.Attachment0, socket.Attachment1 = attachment0, attachment1
						socket.Parent = desc.Parent
						desc:Destroy()
					end	
				end
			end
		end)
	end)
end)

The result is just an idle broken body with the head stuck inside the torso. I am not sure how to create ragdoll suitable for R6. I seen posts but it did not help that much to me. I do understand how to use BallSocketConstraint and to turn off BreakJointsOnDeath but not how to utilize them to create the ragdoll effect.

If anyone has a solution, I’d be appreciated.

I found this

–put on startercharacterscripts
–made this from a tutorial
–i’ll take this as not mine cause i dont know how to script and this was from a tutorial
local humanoid = script.Parent:WaitForChild(“Humanoid”)

humanoid.BreakJointsOnDeath = false

humanoid.Died:Connect(function()
for index,joint in pairs(script.Parent:GetDescendants()) do
if joint:IsA(“Motor6D”) then
local socket = Instance.new(“BallSocketConstraint”)
local a1 = Instance.new(“Attachment”)
local a2 = Instance.new(“Attachment”)
a1.Parent = joint.Part0
a2.Parent = joint.Part1
socket.Parent = joint.Parent
socket.Attachment0 = a1
socket.Attachment1 = a2
a1.CFrame = joint.C0
a2.CFrame = joint.C1
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
joint:Destroy()
end
end
end)