Why do I sometimes die when i get ragdolled

So when someone slaps and gets ragdolled they sometimes randomly die here are the codes: Thanks for the help :smiley: !

local Tool = script.Parent.Parent
local DebrisService = game:GetService("Debris")

local Anim = script:WaitForChild("Animation")
local AnimTrack 

local hitChars = {}
local debounce = false
local MS = game:GetService("MarketplaceService")

local whydeb = false
pcall(function()
	Tool.Activated:Connect(function()
		if debounce then
			return
		end

		debounce = true

		local humanoid = Tool.Parent:FindFirstChildOfClass("Humanoid")

		AnimTrack = humanoid:LoadAnimation(Anim)
		AnimTrack:AdjustSpeed(tonumber(script.Parent.Parent.SoundHandler.Cooldown.Value/2)) 
		AnimTrack:Play()
		wait(tonumber(script.Parent.Parent.SoundHandler.Cooldown.Value))
		debounce = false
	end)

	Tool.Hitbox.Touched:Connect(function(hit)
		if not hit or hitChars[hit.Parent] and hit.Parent ~= Tool.Parent or not debounce  then
			return
		end

		if hit.Parent:FindFirstChild("Humanoid") then
			local eChar = hit.Parent
			local plrChar = Tool.Parent


			if game.Players:GetPlayerFromCharacter(eChar) then
				local ePlr = game.Players:GetPlayerFromCharacter(eChar)


			end
			if eChar:FindFirstChild("Invincible") then
				return
			end


			local eHumanRootPart = eChar:FindFirstChild("HumanoidRootPart")
			local plrHumanRootPart = plrChar:FindFirstChild("HumanoidRootPart")

			if plrHumanRootPart and eHumanRootPart then
				if game.Players:GetPlayerFromCharacter(plrChar):HasTag("Ice") then
					task.spawn(function()
						task.wait(1)
					end)
					local humanoid = eChar:FindFirstChildOfClass("Humanoid")
					local val = Instance.new("NumberValue",eChar)
					val.Name = "OldWps"
					val.Value = humanoid.WalkSpeed
					local val2 = Instance.new("NumberValue",eChar)
					val2.Name = "OldJump"
					val2.Value = humanoid.JumpPower
					local iceclone = game:GetService("ServerStorage"):FindFirstChild("Cube"):Clone()
					iceclone.Parent = workspace
					iceclone.Position = eChar.HumanoidRootPart.Position
					local direction = (eHumanRootPart.CFrame.Position - plrHumanRootPart.CFrame.Position).Unit
					iceclone.LinearVelocity.VectorVelocity = (direction + Vector3.new(0, .3, 0)).Unit * 50
					DebrisService:AddItem(iceclone.LinearVelocity,.7)


					local WeldCons = Instance.new("WeldConstraint",iceclone)
					WeldCons.Part0 = iceclone
					WeldCons.Part1 = eChar.HumanoidRootPart
					humanoid.WalkSpeed = 0
					humanoid.JumpPower = 0
				end
				eChar.Humanoid.Health -= script.Parent.Parent.DealDmg.Value
				if game.Players:GetPlayerFromCharacter(plrChar).HumValues.Strength.Value >= 80 then
					script.Parent.Parent.Hand.HardslapsoundBoom.Volume = .5
					script.Parent.Parent.Hand.HardslapsoundBoom:Play()
				else
					script.Parent.Parent.SoundHandler.SlapSound:Play()	
				end

				script.Parent.Parent.SoundHandler.SlapSound:Play()
				script.Disabled = true



				local force = Instance.new("BodyVelocity", eChar.Head)
				force.MaxForce = Vector3.new(2, 2, 2) * math.huge
				local direction = (eHumanRootPart.CFrame.Position - plrHumanRootPart.CFrame.Position).Unit
				force.Velocity = (direction + Vector3.new(0, 1, 0)).Unit *  if  game.Players:GetPlayerFromCharacter(plrChar):HasTag("Fury") then game.Players:GetPlayerFromCharacter(plrChar).HumValues.Strength.Value *2 else game.Players:GetPlayerFromCharacter(plrChar).HumValues.Strength.Value
				local rotation = Instance.new("BodyAngularVelocity", eHumanRootPart)
				rotation.AngularVelocity = Vector3.new(1,1,1) * math.pi * math.random(1,5)
				rotation.MaxTorque = Vector3.new(2,2,2) * math.huge
				rotation.P = 4999
				script:WaitForChild("RemoteEvent"):FireAllClients(Tool,eChar)
				DebrisService:AddItem(force, 0.35)
				DebrisService:AddItem(rotation, 0.32)
				if game.Players:GetPlayerFromCharacter(plrChar):HasTag("Fury") then
					print("a")
					game.Players:GetPlayerFromCharacter(plrChar):RemoveTag("Fury")
					for _, v in pairs(plrChar.HumanoidRootPart:GetDescendants()) do
						if v:IsA("ParticleEmitter") then
							v.Enabled = false
							task.spawn(function()
								task.wait(.4)
								v:Destroy()
							end)
						end
					end


				end
				if hit.Parent.Humanoid.Health <= 0  and not eChar:HasTag("GaveKill") then
					game.Players:GetPlayerFromCharacter(plrChar).Kills.Value += 1
					eChar:AddTag("GaveKill")
					game.Players:GetPlayerFromCharacter(plrChar).HumValues.Strength.Value += 4
					plrChar.Humanoid.Health += 10
					plrChar.Humanoid.MaxHealth += 20
				end
				if game.Players:GetPlayerFromCharacter(plrChar):HasTag("TruePower") then
					game.Players:GetPlayerFromCharacter(plrChar).HumValues.Strength.Value -= 400
					game.Players:GetPlayerFromCharacter(plrChar):RemoveTag("TruePower")
					plrChar.Humanoid.WalkSpeed -= 30


					for _, v in pairs(plrChar.HumanoidRootPart:GetDescendants()) do
						if v:IsA("ParticleEmitter") then
							v.Enabled = false
							task.spawn(function()
								task.wait(7)
								v:Destroy()
							end)
						end
					end
				end
				task.spawn(function()
					task.spawn(function()
						local Ragdoll = require(game:GetService("ReplicatedStorage"):WaitForChild("RagdollCharacterV1"))
						task.spawn(function()
							if game.Players:GetPlayerFromCharacter(plrChar):HasTag("Ice") then
								game.Players:GetPlayerFromCharacter(plrChar):RemoveTag("Ice")
								local iceclone= workspace :FindFirstChild("Cube")

								local WeldCons
								if iceclone and iceclone:FindFirstChildOfClass("WeldConstraint") then
									WeldCons = iceclone:FindFirstChildOfClass("WeldConstraint")
								end
								local humanoid = eChar:FindFirstChildOfClass("Humanoid")
								local val = eChar:FindFirstChild("OldWps")
								local val2 = eChar:FindFirstChild("OldJump")
								task.wait(script.Parent.Parent.RagdollTimer.Value)
								if WeldCons then
									WeldCons:Destroy()
								end
								iceclone:Destroy()
								humanoid.WalkSpeed = val.Value
								humanoid.JumpPower = val2.Value
								val:Destroy()
								val2:Destroy()

							end
						end)

						Ragdoll.Start(eChar)
						task.wait(script.Parent.Parent.RagdollTimer.Value)
						Ragdoll.Stop(eChar)
					end)
					local Invincible = Instance.new("BoolValue",eChar)
					Invincible.Name = "Invincible"
					task.spawn(function()
						task.wait(script.Parent.Parent.RagdollTimer.Value + .5)
						Invincible:Destroy()
					end)
				end)
				wait(script.Parent.Parent.SoundHandler.Cooldown.Value)

			end
			task.spawn(function()
				if hitChars == nil then
					return 
				end
				if  hit.Parent ~= nil then  script.Disabled = false return end
				if hitChars[hit.Parent] ~= nil then
					hitChars[hit.Parent] = true
					script.Disabled = false
				end





				hitChars[hit.Parent] = nil
			end)	
		end
	end)
end)

Ragdoll Module code:

local Ragdoll = {}
Ragdoll._index = Ragdoll

local function setupRagdollConstraints(character)
	for _, part in pairs(character:GetDescendants()) do
		if part:IsA("Motor6D") then
			local attachment0 = Instance.new("Attachment")
			attachment0.Name = part.Name .. "Attachment0"
			attachment0.CFrame = part.C0
			attachment0.Parent = part.Part0

			local attachment1 = Instance.new("Attachment")
			attachment1.Name = part.Name .. "Attachment1"
			attachment1.CFrame = part.C1
			attachment1.Parent = part.Part1
			local ballSocket = Instance.new("BallSocketConstraint")
			ballSocket.Name = part.Name .. "BallSocketConstraint"
			ballSocket.Attachment0 = attachment0
			ballSocket.Attachment1 = attachment1
			ballSocket.Parent = part.Part0

			ballSocket.LimitsEnabled = true
			ballSocket.TwistLimitsEnabled = true
			ballSocket.UpperAngle = 45
			ballSocket.TwistUpperAngle = 45

			part.Enabled = false
		end
	end

	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.PlatformStand = true
	end
end

local function removeRagdollConstraints(character)
	for _, part in pairs(character:GetDescendants()) do
		if part:IsA("Motor6D") then
			part.Enabled = true
		elseif part:IsA("BallSocketConstraint") or part:IsA("Attachment")  then
			part:Destroy()
		end
	end
	task.spawn(function()
		task.wait(1)
		if character:FindFirstChild("Ragdolled") then
			character:FindFirstChild("Ragdolled"):Destroy()
		end
	end)
	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.PlatformStand = false
	end
end

function Ragdoll.Start(character)
	if character and character:FindFirstChild("Humanoid") and not character:FindFirstChild("Ragdolled") then
		setupRagdollConstraints(character)
	end
end

function Ragdoll.Stop(character)
	if character and character:FindFirstChild("Humanoid") then
		removeRagdollConstraints(character)

		local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
		end

		local hrp = character:FindFirstChild("HumanoidRootPart")
		if hrp then
			hrp.CFrame = CFrame.new(hrp.Position)
			hrp.Velocity = Vector3.new(0, 0, 0)
		end


	end
end

return Ragdoll

Is it supposed to kill them after one slap or is it randomly killing the player when it’s not supposed to?

its not supposed to be killing

i think its a problem with the ragdoll system but idk

It’s probably killing the player because maybe the head is being moved, because in Roblox Studio if a head is moved then the character gets killed. So something in your script may be making the head move probably.

maybe the bodyforce or hm the ragdoll constraint can maybe do that too

Yeah, possibly I don’t know much about ragdoll systems but maybe that’s a possible cause.

I mean it gets descendants from all the player and then remove the ball socket constraint. but i dont know tbh

maybe i can get anotther ragdoll system and try that one

I just saw some more ragdoll system and still, it just does the same thing

i think i see, it changes motor6d’s enabled is to false and then sets to truewhen u put motor 6ds to false enabled u get killed