Function will not work

function replaceLegs not working and there are no errors.

→ Necessary for Ragdolling to function properly
Character.Humanoid.BreakJointsOnDeath = false
Character.Humanoid.RequiresNeck = false

→ Specific CFrame’s I made for the best looking Ragdoll

local ArmCFrames = {
[“Neck”] = {CFrame.new(0, 1, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1), CFrame.new(0, -0.5, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1)},
[“Left Shoulder”] = {CFrame.new(-1.3, 0.75, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1), CFrame.new(0.2, 0.75, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1)},
[“Right Shoulder”] = {CFrame.new(1.3, 0.75, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1), CFrame.new(-0.2, 0.75, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)},
}

local LegCFrames = {
[“Neck”] = {CFrame.new(0, 1, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1), CFrame.new(0, -0.5, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1)},
[“Left Hip”] = {CFrame.new(-0.5, -1.5, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1), CFrame.new(0, 0.5, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1)},
[“Right Hip”] = {CFrame.new(0.5, -1.5, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1), CFrame.new(0, 0.5, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1)},
}

local ragdollInstanceNames = {
[“RagdollAttachment”] = true,
[“Attachment0”] = true,
[“Attachment1”] = true,
[“Attachment2”] = true,
[“Attachment3”] = true,
[“RagdollConstraint1”] = true,
[“ColliderPart”] = true,
}

→ Used to trigger Ragdoll
local RagdollValue = Instance.new(“BoolValue”)
RagdollValue.Name = “IsRagdoll”
RagdollValue.Parent = Character

→ Allows for proper limb collisions
local function createColliderPart(part: BasePart)
if not part then return end
local rp = game.ServerStorage.MeshPart:Clone() --Instance.new(“Part”)
rp.Name = “ColliderPart”
rp.Size = part.Size/1.2
rp.Massless = true
rp.CFrame = part.CFrame
rp.Transparency = 1
local D = 2 --Change
local E = 0 --Change
local EW = 0 --Change
local F = 2 --Change
local FW = 100 --Change
rp.CustomPhysicalProperties = PhysicalProperties.new(D, F, E, FW, EW)

local wc = Instance.new("WeldConstraint")
wc.Part0 = rp
wc.Part1 = part

wc.Parent = rp
rp.Parent = part

end

function replaceArms()
Humanoid.AutoRotate = false
for _, ArmMotors: Motor6D in pairs(Character:GetDescendants()) do
if ArmMotors:IsA(“Motor6D”) then
if not ArmCFrames[ArmMotors.Name] then return end
ArmMotors.Enabled = false;
local a0, a1 = Instance.new(“Attachment”), Instance.new(“Attachment”)
a0.CFrame = ArmCFrames[ArmMotors.Name][1]
a1.CFrame = ArmCFrames[ArmMotors.Name][2]

a0.Name = “Attachment0”
a1.Name = “Attachment1”

createColliderPart(ArmMotors.Part1)

local b = Instance.new(“RopeConstraint”)
b.Attachment0 = a0
b.Attachment1 = a1
b.Name = “RagdollConstraint1”
b.Length = 0.3

a0.Parent = ArmMotors.Part0
a1.Parent = ArmMotors.Part1
b.Parent = ArmMotors.Parent
end
end
end

function replaceLegs()
for _, LegMotors: Motor6D in pairs(Character:GetDescendants()) do
if LegMotors:IsA(“Motor6D”) then
if not LegCFrames[LegMotors.Name] then return end
LegMotors.Enabled = false;
local a2, a3 = Instance.new(“Attachment”), Instance.new(“Attachment”)
a2.CFrame = LegCFrames[LegMotors.Name][1]
a3.CFrame = LegCFrames[LegMotors.Name][2]

a2.Name = “Attachment2”
a3.Name = “Attachment3”

createColliderPart(LegMotors.Part1)

local c = Instance.new(“BallSocketConstraint”)
c.Attachment0 = a2
c.Attachment1 = a3
c.Name = “RagdollConstraint2”
c.Radius = 0.15
c.LimitsEnabled = true
c.TwistLimitsEnabled = false
c.UpperAngle = 180
c.TwistLowerAngle = -22.5
c.TwistUpperAngle = 22.5

a2.Parent = LegMotors.Part0
a3.Parent = LegMotors.Part1
c.Parent = LegMotors.Parent
end
end
end

→ Destroys all Ragdoll made instances and re-enables the Motor6D’s
function resetJoints()
if Humanoid.Health < 1 then return end
for _, instance in pairs(Character:GetDescendants()) do
if ragdollInstanceNames[instance.Name] then
instance:Destroy()
end

	if instance:IsA("Motor6D") then
		instance.Enabled = true;
	end
end
Humanoid.AutoRotate = true

end

local hc = Instance.new(“WeldConstraint”)
local h = script.Parent:WaitForChild(“Head”)
hc.Parent = h
hc.Part0 = h
hc.Part1 = script.Parent:WaitForChild(“Torso”)

function Arms(value: boolean)
if value then
replaceArms()
else
resetJoints()
end
end

function Legs(value: boolean)
if value then
replaceLegs()
else
resetJoints()
end
end


→ Connect the Events
RagdollValue.Changed:Connect(Arms, Legs)
Humanoid.Died:Once(function() → The only non perfect part about this is the oof sound plays twice for some reason
RagdollValue.Value = true
end)

A little hard to read. Can it be reformatted—for the sake of everyone trying to help you. Would be appreciated :wut:


Character.Humanoid.BreakJointsOnDeath = false
Character.Humanoid.RequiresNeck = false

local ArmCFrames = {
	[“Neck”] = {CFrame.new(0, 1, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1), CFrame.new(0, -0.5, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1)},
	[“Left Shoulder”] = {CFrame.new(-1.3, 0.75, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1), CFrame.new(0.2, 0.75, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1)},
	[“Right Shoulder”] = {CFrame.new(1.3, 0.75, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1), CFrame.new(-0.2, 0.75, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)},
}

local LegCFrames = {
	[“Neck”] = {CFrame.new(0, 1, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1), CFrame.new(0, -0.5, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1)},
	[“Left Hip”] = {CFrame.new(-0.5, -1.5, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1), CFrame.new(0, 0.5, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1)},
	[“Right Hip”] = {CFrame.new(0.5, -1.5, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1), CFrame.new(0, 0.5, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1)},
}

local ragdollInstanceNames = {
	[“RagdollAttachment”] = true,
	[“Attachment0”] = true,
	[“Attachment1”] = true,
	[“Attachment2”] = true,
	[“Attachment3”] = true,
	[“RagdollConstraint1”] = true,
	[“ColliderPart”] = true,
}
→ Used to trigger Ragdoll
local RagdollValue = Instance.new(“BoolValue”)
RagdollValue.Name = “IsRagdoll”
RagdollValue.Parent = Character

local function createColliderPart(part: BasePart)
	if not part then return end
	local rp = game.ServerStorage.MeshPart:Clone() --Instance.new(“Part”)
	rp.Name = “ColliderPart”
	rp.Size = part.Size/1.2
	rp.Massless = true
	rp.CFrame = part.CFrame
	rp.Transparency = 1
	local D = 2 --Change
	local E = 0 --Change
	local EW = 0 --Change
	local F = 2 --Change
	local FW = 100 --Change
	rp.CustomPhysicalProperties = PhysicalProperties.new(D, F, E, FW, EW)

	local wc = Instance.new("WeldConstraint")
	wc.Part0 = rp
	wc.Part1 = part

	wc.Parent = rp
	rp.Parent = part

end

function replaceArms()
	Humanoid.AutoRotate = false
	for _, ArmMotors: Motor6D in pairs(Character:GetDescendants()) do
		if ArmMotors:IsA(“Motor6D”) then
			if not ArmCFrames[ArmMotors.Name] then return end
			ArmMotors.Enabled = false;
			local a0, a1 = Instance.new(“Attachment”), Instance.new(“Attachment”)
			a0.CFrame = ArmCFrames[ArmMotors.Name][1]
			a1.CFrame = ArmCFrames[ArmMotors.Name][2]
			–
			a0.Name = “Attachment0”
			a1.Name = “Attachment1”
			–
			createColliderPart(ArmMotors.Part1)
			–
			local b = Instance.new(“RopeConstraint”)
			b.Attachment0 = a0
			b.Attachment1 = a1
			b.Name = “RagdollConstraint1”
			b.Length = 0.3
			–
			a0.Parent = ArmMotors.Part0
			a1.Parent = ArmMotors.Part1
			b.Parent = ArmMotors.Parent
		end
	end
end
function replaceLegs()
	for _, LegMotors: Motor6D in pairs(Character:GetDescendants()) do
		if LegMotors:IsA(“Motor6D”) then
			if not LegCFrames[LegMotors.Name] then return end
			LegMotors.Enabled = false;
			local a2, a3 = Instance.new(“Attachment”), Instance.new(“Attachment”)
			a2.CFrame = LegCFrames[LegMotors.Name][1]
			a3.CFrame = LegCFrames[LegMotors.Name][2]
			–
			a2.Name = “Attachment2”
			a3.Name = “Attachment3”
			–
			createColliderPart(LegMotors.Part1)
			–
			local c = Instance.new(“BallSocketConstraint”)
			c.Attachment0 = a2
			c.Attachment1 = a3
			c.Name = “RagdollConstraint2”
			c.Radius = 0.15
			c.LimitsEnabled = true
			c.TwistLimitsEnabled = false
			c.UpperAngle = 180
			c.TwistLowerAngle = -22.5
			c.TwistUpperAngle = 22.5
			–
			a2.Parent = LegMotors.Part0
			a3.Parent = LegMotors.Part1
			c.Parent = LegMotors.Parent
		end
	end
end

→ Destroys all Ragdoll made instances and re-enables the Motor6D’s
function resetJoints()
	if Humanoid.Health < 1 then return end
	for _, instance in pairs(Character:GetDescendants()) do
		if ragdollInstanceNames[instance.Name] then
			instance:Destroy()
		end

		if instance:IsA("Motor6D") then
			instance.Enabled = true;
		end
	end
	Humanoid.AutoRotate = true

end
local hc = Instance.new(“WeldConstraint”)
local h = script.Parent:WaitForChild(“Head”)
hc.Parent = h
hc.Part0 = h
hc.Part1 = script.Parent:WaitForChild(“Torso”)

function Arms(value: boolean)
	if value then
		replaceArms()
	else
		resetJoints()
	end
end

function Legs(value: boolean)
	if value then
		replaceLegs()
	else
		resetJoints()
	end
end

RagdollValue.Changed:Connect(Arms, Legs)
Humanoid.Died:Once(function() 
	RagdollValue.Value = true
end)

i fixed it i just make every limb have indivisual constraints.