Every time I use my ragdoll it kills a player

Every time I use my ragdoll, it kills a player as if something important is being deleted. I tried searching for the bug but couldn’t find anything. Can you help me?

server script


HumanoidTarget:ChangeState(Enum.HumanoidStateType.Physics)
	
local motors = Ragdoll.CreateJoints(TargetCharacter)
Ragdoll.Ragdoll(TargetCharacter)
Ragdoll.SetMotorsEnabled(motors, false)


task.delay(2, function()
	if not TargetPlayer then
		return
	end
		
	HumanoidTarget:ChangeState(Enum.HumanoidStateType.GettingUp)

	Ragdoll.DestroyJoints(TargetCharacter)
	Ragdoll.SetMotorsEnabled(motors, true)
	Ragdoll.UnRagdoll(TargetCharacter)
end)

Radgdol Module

-- Ragdoll Module
-- Made by Dev1n @ADRENALXNE

local PS = game:GetService('Players')
local RPS = game:GetService('ReplicatedStorage')

local stateType = Enum.HumanoidStateType

local RAGDOLL_NAME = 'RagdollConstraint'
local NOCOLLIDE_NAME = 'RagdollNoCollide'

local noCollisionMap = {
	R15 = {
		Head = {'LeftUpperArm', 'LeftUpperLeg', 'LowerTorso', 'RightUpperArm', 'RightUpperLeg'},
		LeftFoot = {'LowerTorso', 'UpperTorso'},
		LeftHand = {'LowerTorso', 'UpperTorso'},
		RightFoot = {'LowerTorso', 'UpperTorso'},
		RightHand = {'LowerTorso', 'UpperTorso'},
		LeftLowerArm = {'LowerTorso', 'UpperTorso'},
		LeftLowerLeg = {'LowerTorso', 'UpperTorso'},
		LeftUpperArm = {'LeftUpperLeg', 'LowerTorso', 'UpperTorso', 'RightUpperArm', 'RightUpperLeg'},
		LeftUpperLeg = {'LowerTorso', 'UpperTorso', 'RightUpperLeg'},
		RightLowerArm = {'LowerTorso', 'UpperTorso'},
		RightLowerLeg = {'LowerTorso', 'UpperTorso'},
		RightUpperArm = {'RightUpperLeg', 'LowerTorso', 'UpperTorso', 'LeftUpperLeg'},
		RightUpperLeg = {'LowerTorso', 'UpperTorso'},
	},
	
	R6 = {
		Head = {'Left Arm', 'Left Leg', 'Torso', 'Right Arm', 'Right Leg'},
	}
}

local function getMotors(character : Model) : {Motor6D}
	local t : {Motor6D} = {}
	local humanoid : Humanoid = character.Humanoid
	
	for _,part in character:GetChildren() do
		for _, descendant in part:GetChildren() do
			if descendant:IsA('Motor6D') then
				t[#t + 1] = descendant
			end
		end
	end
	
	return t
end

-- create NoCollisionConstraints so the character doesn't fling
local function createNoCollisionConstraints(character, rigTypeName)
	for i,subMap in noCollisionMap[rigTypeName] do
		for _,x in subMap do
			local noCollision = Instance.new('NoCollisionConstraint')
			noCollision.Name = NOCOLLIDE_NAME
			noCollision.Part0 = character[i]
			noCollision.Part1 = character[x]
			noCollision.Parent = character
			
		end
	end
end

-- Ragdoll Module
local Ragdoll = {}

-- Create joints for ragdoll
function Ragdoll.CreateJoints(character : Model) : {Motor6D}
	if not character:IsA('Model') or not character:FindFirstChildOfClass('Humanoid') then
		return
	end
	
	local rigType = character.Humanoid.RigType
	local motors = getMotors(character)
	
	createNoCollisionConstraints(character, rigType.Name)
	
	for _, motor in motors do
		local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
		a0.Name, a1.Name = RAGDOLL_NAME, RAGDOLL_NAME
		a0.CFrame = motor.C0
		a1.CFrame = motor.C1
		a0.Parent = motor.Part0
		a1.Parent = motor.Part1

		local name = motor.Name:gsub('Right', '')
		name = name:gsub('Left', '')
		name = name:gsub('Joint', '')
		name = name:gsub(' ', '')
		
		local b = (script[rigType.Name]:FindFirstChild(name) or script[rigType.Name].Default):Clone()
		b.Name = RAGDOLL_NAME

		b.Attachment0 = a0
		b.Attachment1 = a1
		b.Parent = motor.Part1
	end
	
	return motors
end

-- Remove joints for ragdoll
function Ragdoll.DestroyJoints(character : Model)
	for _, descendant : Instance in character:GetDescendants() do
		-- Remove BallSockets and NoCollides, leave the additional Attachments
		if (descendant:IsA('Constraint') or descendant:IsA('WeldConstraint') or descendant:IsA('Attachment')) and descendant.Name == RAGDOLL_NAME
			or descendant:IsA("NoCollisionConstraint") and descendant.Name == NOCOLLIDE_NAME
		then
			descendant:Destroy()
		end
	end
end

-- Setup properties for Ragdoll
function Ragdoll.Ragdoll(character : Model)
	
	local rootPart : BasePart? = character.PrimaryPart
	local humanoid : Humanoid = character.Humanoid
	
	humanoid.WalkSpeed = 0
	humanoid.AutoRotate = false
	rootPart.CanCollide = false
	character.Head.CanCollide = true
	
	
	if not character.PrimaryPart:GetNetworkOwner() then
		if humanoid.Health > 0 and humanoid:GetState() ~= stateType.Physics then
			humanoid:ChangeState(stateType.Physics)
		end
	end
end

-- Reset properties for ragdoll
function Ragdoll.UnRagdoll(character : Model)
	local humanoid : Humanoid = character.Humanoid
	
	if humanoid.Health > 0 then
		humanoid.WalkSpeed = 16
		humanoid.AutoRotate = true
		character.PrimaryPart.CanCollide = true
		character.Head.CanCollide = false
		
		if not character.PrimaryPart:GetNetworkOwner() then
			if humanoid:GetState() ~= stateType.GettingUp then
				humanoid:ChangeState(stateType.GettingUp)
			end
		end
	end
end

-- Set motor-set enabled
function Ragdoll.SetMotorsEnabled(motors : {Motor6D}, enabled : boolean)
	for _, motor in motors do
		motor.Enabled = enabled
	end
end

-- Check whether a humanoid is ragdolled or not
function Ragdoll.IsRagdolled(humanoid : Humanoid) : boolean
	return humanoid:GetState() == stateType.Physics
end

return Ragdoll

I feel that the problem is in SetMotorsEnabled because it happens as soon as ragdoll happens.
and sometime it’s removing player hair for no reason

image

Thank you :relaxed:

1 Like

The problem is in the humanoid just make it nedd neck to false and ig it’s will work

i already fix it
it’s not about humanoid it’s about delay

It takes too long to change from server-side to client-side even the buffer takes some time that’s why Motor6D getting delete before chaging state in client-side before adding the new WeldConstraint and Constraint because of that the player keep dying everytime using ragdoll because there is a delay

About the accessory it’s simple (e.g there is a WeldConstraint just use FindFirstAncestorOfClass to search if there a accessory)

It kills the char bc ur removing the neck and it taks a moment before the client recognizes the ballsocket being the new neck, so doign it from client or jsut turning off requires neck works

2 Likes

Yeah that what i’m saying :sob:
There’s a delay, I just Turned the neck off, I don’t really want to do everything on the client, it’ll take me some time

1 Like

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