Ragdoll that has attachments attached to humanoidrootpart dies when the ragdoll state is toggled

Hey–I want to figure out why my ragdoll system makes humanoids die when the ball-socket constraints are attached to the humanoidrootpart but it looks completely normal

1: Humanoid dies when ragdoll state is enabled

2: Everything looks completely normal

I tried looking at other posts on devforum and found no solutions and I attempted to fix it myself but ended up breaking it even more.

Here’s my code:

local respawnable = true
local respawntime = 0
if respawnable == true then
	respawntime = 15
	respawnclone = script.Parent:Clone()
end

local character = script.Parent
local humanoid = character.Humanoid
--humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
--humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
local hrp = character.HumanoidRootPart
humanoid.BreakJointsOnDeath = false --MANDATORY
local jointsfolder = script.Constraints

local ragdolled = character.Ragdolled
local armballcolliders = false
local legballcolliders = false

local randomdeathfaces = {"4820464519", "4841508676", "2805269620", "9605698115", "9352717834", "33328967", "82908315", "7236332343", "255719185", "14484043271"}
local randomdeathsounds = {"6927884261", "6932519682", "8930566431", "2299243257", "877221802", "4164190231", "58435367"}
local function deathstuff()
	local face = character.Head.face
	face.Texture = "rbxassetid://" .. randomdeathfaces[math.random(#randomdeathfaces)]
	local sound = Instance.new("Sound", character.Head)
	sound.Volume = 0.5
	sound.SoundId = "rbxassetid://" .. randomdeathsounds[math.random(#randomdeathsounds)]
	sound:Play()
end

local function setupcollisionparts(char : Model)
	for _, v in ipairs(char:GetChildren()) do
		if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
			v.CollisionGroup = "ragdollcollidersnoc"
			if v.Name == "Right Arm" or v.Name == "Left Arm" or v.Name == "Right Leg" or v.Name == "Left Leg" then
				local bf = Instance.new("BodyForce", v)
				bf.Force = Vector3.new(0, 100, 0)
			end
		end
	end
end

local function setupragdoll(char : Model)
	for _, motor in ipairs(char:GetDescendants()) do
		if motor:IsA("Motor6D") then
			if motor.Name == "Right Shoulder" then
				local a1 = Instance.new("Attachment")
				local a2 = Instance.new("Attachment")
				a1.Parent = hrp
				a2.Parent = motor.Part1
				local sc = script.Constraints.RightArmBSC:Clone()
				sc.Parent = hrp
				sc.Attachment0 = a1
				sc.Attachment1 = a2
				a1.Position = motor.C0.Position + CFrame.new(0.5, 0.25, 0).Position
				a2.Position = motor.C1.Position + CFrame.new(0.5, 0.25, 0).Position
				task.wait(0.1)
				motor.Enabled = false
			elseif motor.Name == "Left Shoulder" then
				local a1 = Instance.new("Attachment")
				local a2 = Instance.new("Attachment")
				a1.Parent = hrp
				a2.Parent = motor.Part1
				local sc = script.Constraints.LeftArmBSC:Clone()
				sc.Parent = hrp
				sc.Attachment0 = a1
				sc.Attachment1 = a2
				a1.Position = motor.C0.Position + CFrame.new(-0.5, 0.25, 0).Position
				a2.Position = motor.C1.Position + CFrame.new(-0.5, 0.25, 0).Position
				task.wait(0.1)
				motor.Enabled = false
			elseif motor.Name == "Right Hip" then
				local a1 = Instance.new("Attachment")
				local a2 = Instance.new("Attachment")
				a1.Parent = hrp
				a2.Parent = motor.Part1
				local sc = script.Constraints.RightLegBSC:Clone()
				sc.Parent = hrp
				sc.Attachment0 = a1
				sc.Attachment1 = a2
				a1.Position = motor.C0.Position + CFrame.new(-0.5, 0, 0).Position
				a2.Position = motor.C1.Position + CFrame.new(-0.5, 0, 0).Position
				task.wait(0.1)
				motor.Enabled = false
			elseif motor.Name == "Left Hip" then
				local a1 = Instance.new("Attachment")
				local a2 = Instance.new("Attachment")
				a1.Parent = hrp
				a2.Parent = motor.Part1
				local sc = script.Constraints.LeftLegBSC:Clone()
				sc.Parent = hrp
				sc.Attachment0 = a1
				sc.Attachment1 = a2
				a1.Position = motor.C0.Position + CFrame.new(0.5, 0, 0).Position
				a2.Position = motor.C1.Position + CFrame.new(0.5, 0, 0).Position
				task.wait(0.1)
				motor.Enabled = false
			elseif motor.Name == "Neck" then
				local a1 = Instance.new("Attachment")
				local a2 = Instance.new("Attachment")
				a1.Parent = hrp
				a2.Parent = motor.Part1
				local sc = script.Constraints.HeadBSC:Clone()
				sc.Parent = hrp
				sc.Attachment0 = a1
				sc.Attachment1 = a2
				a1.Position = motor.C0.Position
				a2.Position = motor.C1.Position
				task.wait(0.1)
				motor.Enabled = false
			end
		end
	end
end

local function replacesockets(char : Model)
	for _, socket in ipairs(char:GetDescendants()) do
		if socket:IsA("BallSocketConstraint") and socket.Parent ~= jointsfolder then
			socket:Destroy()
		end
	end
	for i, motor6d in pairs(char:GetDescendants()) do
		if motor6d:IsA("Motor6D") then
			motor6d.Enabled = true
		end
	end
	for i, attachment in pairs(char:GetDescendants()) do
		if attachment:IsA("Attachment") and attachment.Name == "Attachment" then
			attachment:Destroy()
		end
	end
	for _, part in ipairs(char:GetDescendants()) do
		if part:IsA("BasePart") and part.Name ~= "RagdollCollider" then
			part.CollisionGroup = "Default"
		elseif part:IsA("BasePart") and part.Name == "RagdollCollider" then
			part:Destroy()
		end
	end
	for _, force in ipairs(char:GetDescendants()) do
		if force:IsA("BodyForce") then
			force:Destroy()
		end
	end
end

humanoid.Died:Connect(function()
	ragdolled.Value = true
	deathstuff()
	if respawnable == true then
		task.delay(respawntime, function()
			script.Parent:Destroy()
			respawnclone.Parent = workspace
		end)
	end
end)

ragdolled.Changed:Connect(function(value)
	if value == true then
		task.spawn(function()
			setupcollisionparts(character)
		end)
		task.spawn(function()
			setupragdoll(character)
		end)
	elseif value == false then
		hrp.CFrame = CFrame.new(hrp.CFrame.Position)
		task.spawn(function()
			replacesockets(character)
		end)
	end
end)

This code is messy as I’m not an experienced developer

I think it may be a problem with Roblox’s physics but I would need confirmation

I am not sure about the issue
i can only think the issue was attaching the constraints to the humanoidrootpart will cause issues with character movements have you tries Torso and kept the humanoidrootpart connected?

local respawnable = true
local respawntime = 0
if respawnable == true then
	respawntime = 15
	respawnclone = script.Parent:Clone()
end

local character = script.Parent
local humanoid = character.Humanoid
local hrp = character.HumanoidRootPart
local torso = character:FindFirstChild("Torso")
humanoid.BreakJointsOnDeath = false
local jointsfolder = script.Constraints

local ragdolled = character.Ragdolled
local armballcolliders = false
local legballcolliders = false

local randomdeathfaces = {"4820464519", "4841508676", "2805269620", "9605698115", "9352717834", "33328967", "82908315", "7236332343", "255719185", "14484043271"}
local randomdeathsounds = {"6927884261", "6932519682", "8930566431", "2299243257", "877221802", "4164190231", "58435367"}

local function deathstuff()
	local face = character.Head.face
	face.Texture = "rbxassetid://" .. randomdeathfaces[math.random(#randomdeathfaces)]
	local sound = Instance.new("Sound", character.Head)
	sound.Volume = 0.5
	sound.SoundId = "rbxassetid://" .. randomdeathsounds[math.random(#randomdeathsounds)]
	sound:Play()
end

local function setupcollisionparts(char : Model)
	for _, v in ipairs(char:GetChildren()) do
		if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
			v.CollisionGroup = "ragdollcollidersnoc"
			if v.Name == "Right Arm" or v.Name == "Left Arm" or v.Name == "Right Leg" or v.Name == "Left Leg" then
				local bf = Instance.new("BodyForce", v)
				bf.Force = Vector3.new(0, 100, 0)
			end
		end
	end
end

local function setupragdoll(char : Model)
	humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	for _, motor in ipairs(char:GetDescendants()) do
		if motor:IsA("Motor6D") then
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")
			a1.Parent = torso
			a2.Parent = motor.Part1
			local sc = script.Constraints[motor.Name .. "BSC"]:Clone()
			sc.Parent = torso
			sc.Attachment0 = a1
			sc.Attachment1 = a2
			
			if motor.Name == "Right Shoulder" then
				a1.Position = Vector3.new(1, 0.5, 0)
				a2.Position = Vector3.new(-0.5, 0.5, 0)
			elseif motor.Name == "Left Shoulder" then
				a1.Position = Vector3.new(-1, 0.5, 0)
				a2.Position = Vector3.new(0.5, 0.5, 0)
			elseif motor.Name == "Right Hip" then
				a1.Position = Vector3.new(0.5, -1, 0)
				a2.Position = Vector3.new(0, 1, 0)
			elseif motor.Name == "Left Hip" then
				a1.Position = Vector3.new(-0.5, -1, 0)
				a2.Position = Vector3.new(0, 1, 0)
			elseif motor.Name == "Neck" then
				a1.Position = Vector3.new(0, 1, 0)
				a2.Position = Vector3.new(0, -0.5, 0)
			end
			
			task.wait(0.1)
			motor.Enabled = false
		end
	end
end

local function keepHRPConnected(char : Model)
    local weld = Instance.new("Weld")
    weld.Part0 = hrp
    weld.Part1 = torso
    weld.C0 = CFrame.new(0, 0, 0)
    weld.Parent = hrp
end

local function replacesockets(char : Model)
	for _, socket in ipairs(char:GetDescendants()) do
		if socket:IsA("BallSocketConstraint") and socket.Parent ~= jointsfolder then
			socket:Destroy()
		end
	end
	for i, motor6d in pairs(char:GetDescendants()) do
		if motor6d:IsA("Motor6D") then
			motor6d.Enabled = true
		end
	end
	for i, attachment in pairs(char:GetDescendants()) do
		if attachment:IsA("Attachment") and attachment.Name == "Attachment" then
			attachment:Destroy()
		end
	end
	for _, part in ipairs(char:GetDescendants()) do
		if part:IsA("BasePart") and part.Name ~= "RagdollCollider" then
			part.CollisionGroup = "Default"
		elseif part:IsA("BasePart") and part.Name == "RagdollCollider" then
			part:Destroy()
		end
	end
	for _, force in ipairs(char:GetDescendants()) do
		if force:IsA("BodyForce") then
			force:Destroy()
		end
	end
	for _, weld in ipairs(char:GetDescendants()) do
		if weld:IsA("Weld") and weld.Parent == hrp then
			weld:Destroy()
		end
	end
end

humanoid.Died:Connect(function()
	ragdolled.Value = true
	deathstuff()
	if respawnable == true then
		task.delay(respawntime, function()
			script.Parent:Destroy()
			respawnclone.Parent = workspace
		end)
	end
end)

ragdolled.Changed:Connect(function(value)
	if value == true then
		task.spawn(function()
			setupcollisionparts(character)
		end)
		task.spawn(function()
			setupragdoll(character)
		end)
		task.spawn(function()
			keepHRPConnected(character)
		end)
	elseif value == false then
		hrp.CFrame = CFrame.new(hrp.CFrame.Position)
		task.spawn(function()
			replacesockets(character)
		end)
		humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	end
end)

Have you tried turning off “requiresneck” on the humanoid properties? also you should probably put the attachments into the torso instead

I found out it works better if I attach them to the torso rather to the humanoidrootpart, thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.