Same ragdoll script won't work in new places

I have a Ragdoll script that I’ve been using for some months. In games that I made in january it worked with NPCs and Players. I’ve been rewritting the game code in a new place. But the only thing that isn’t working is the ragdoll script. When I copy and paste the “older” npcs in it, It works but not with “newer” ones neither players (Still works in the old game tho). I have the same Avatar and World settings. I don’t know what to do…


local Players = game:GetService(“Players”)
local Debris = game:GetService(“Debris”)

local Ragdoll = {}
local SavedGroups = {}

Ragdoll.StartRagdoll = function(Character)
if not Character or Character:FindFirstChild(“Ragdoll”) then return end

local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local RootPart = Character:FindFirstChild("HumanoidRootPart")

if not Humanoid or not RootPart or RootPart.Anchored then return end

if Humanoid.Health <= 0 then
	Humanoid.BreakJointsOnDeath = false
end

for _, AnimationTrack in ipairs(Humanoid:GetPlayingAnimationTracks()) do
	AnimationTrack:Stop()
end

--Character:SetAttribute("IFrames", true)

Humanoid.PlatformStand = true
Humanoid.AutoRotate = false
Humanoid.RequiresNeck = false
Humanoid.BreakJointsOnDeath = false

Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false) 
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, true) 

local ragdollValue = Instance.new("BoolValue")
ragdollValue.Name = "Ragdoll"
ragdollValue.Parent = Character

for _, v in ipairs(Character:GetDescendants()) do
	if v:IsA("Motor6D") and v.Name ~= "Root" then
		local part0 = v.Part0
		local part1 = v.Part1

		if part0 and part1 then
			local ballSocket = Instance.new("BallSocketConstraint")
			ballSocket.Name = "RagdollConstraint"

			ballSocket.LimitsEnabled = true
			ballSocket.UpperAngle = 30 
			ballSocket.TwistLimitsEnabled = true
			ballSocket.TwistLowerAngle = -30
			ballSocket.TwistUpperAngle = 30

			ballSocket.MaxFrictionTorque = 250 
			ballSocket.Restitution = 0 

			local attachment0 = Instance.new("Attachment", part0)
			local attachment1 = Instance.new("Attachment", part1)
			attachment0.Name = "RagdollAttachment"
			attachment1.Name = "RagdollAttachment"
			attachment0.CFrame = v.C0
			attachment1.CFrame = v.C1

			ballSocket.Attachment0 = attachment0
			ballSocket.Attachment1 = attachment1
			ballSocket.Parent = part0

			local noCollision = Instance.new("NoCollisionConstraint")
			noCollision.Name = "RagdollNoCollision"
			noCollision.Part0 = part0
			noCollision.Part1 = part1
			noCollision.Parent = part0

			v.Enabled = false 
		end
	end
end

SavedGroups[Character] = {}
local player = Players:GetPlayerFromCharacter(Character)

for _, v in ipairs(Character:GetChildren()) do
	if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
		local collider = v:Clone()
		collider:ClearAllChildren()
		collider.Name = "RagdollCollider"
		collider.Transparency = 1
		collider.CanCollide = true
		collider.Anchored = false
		collider.Massless = false 
		collider.Size = collider.Size * 0.85 
		collider.CFrame = v.CFrame

		SavedGroups[Character][v] = v.CollisionGroup
		v.CollisionGroup = "Ragdoll"
		collider.CollisionGroup = "Ragdoll"

		local weld = Instance.new("WeldConstraint")
		weld.Name = "RagdollColliderWeld"
		weld.Part0 = v
		weld.Part1 = collider
		weld.Parent = collider

		collider.Parent = Character

	end
end

RootPart.CanCollide = false
RootPart.Massless = true

end

Ragdoll.EndRagdoll = function(Character)
if not Character then return end

local Humanoid = Character:FindFirstChildOfClass("Humanoid")
if Humanoid and Humanoid.Health <= 0 then return end

local RootPart = Character:FindFirstChild("HumanoidRootPart")

for _, v in ipairs(Character:GetDescendants()) do
	if v.Name == "RagdollConstraint" or v.Name == "RagdollAttachment" or v.Name == "Ragdoll" or v.Name == "RagdollCollider" or v.Name == "RagdollNoCollision" then
		v:Destroy()
	elseif v:IsA("Motor6D") then
		v.Enabled = true
	end
end

if SavedGroups[Character] then
	for part, oldGroup in pairs(SavedGroups[Character]) do
		if part and part.Parent then
			part.CollisionGroup = oldGroup
		end
	end
	SavedGroups[Character] = nil
end

if RootPart then
	RootPart.Massless = false
	RootPart.Velocity = Vector3.zero 
	RootPart.RotVelocity = Vector3.zero

	local x, y, z = RootPart.CFrame:ToEulerAnglesYXZ()
	RootPart.CFrame = CFrame.new(RootPart.Position + Vector3.new(0, 3, 0)) * CFrame.Angles(0, y, 0)
end

if Humanoid then

	local player = Players:GetPlayerFromCharacter(Character)
	if player then
		for _, part in ipairs(Character:GetDescendants()) do
			if part:IsA("BasePart") and not part.Anchored and part:CanSetNetworkOwnership() then
				pcall(function()
					part:SetNetworkOwner(player)
				end)
			end
		end
	end

	Humanoid.RequiresNeck = true
	Humanoid.PlatformStand = false
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	Humanoid.AutoRotate = true

	task.delay(0.1, function()
		if Humanoid.Parent then
			--Character:SetAttribute("IFrames", false)
		end
	end)
end

end

Ragdoll.DurationRagdoll = function(Character, Duration)
task.spawn(function()
Ragdoll.StartRagdoll(Character)
task.wait(Duration)

	if Character and Character:FindFirstChild("Humanoid") and Character.Humanoid.Health > 0 then
		Ragdoll.EndRagdoll(Character)
	end
end)

end

return Ragdoll


Solved! I had this “AvatarJointUpgrade” on… I didn’t even knew what was that until I went reading updates here in the forum… But done! Wish this helps for anyone reading
This kept me days stuck lol

you should have added “nvm”
because I love when OP solves his problem with this word.

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