Ragdoll gets launched and gets a arm or leg detached when not dying due to an explosion

Hello everyone

i made a system where if a player dies due to an explosion, he gets launched in the air and gets calculated where he should get launched based off of the explosion

the problem is that even if i reset or die due to a bullet, the duplicated character still gets launched and gets his arm or leg detached…

any suggestions?
script goes into serverscriptservice:

local players = game:GetService("Players")
local debris = game:GetService("Debris")

local CORPSE_LIFETIME = 999 -- Time in seconds before the ragdoll is removed

-- Function to create a ragdoll for R6 characters
local function makeRagDoll(doll)
	for _, part in ipairs(doll:GetDescendants()) do
		if part:IsA("Motor6D") then
			local socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")

			a1.Parent = part.Part0
			a2.Parent = part.Part1
			socket.Parent = part.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2

			a1.CFrame = part.C0
			a2.CFrame = part.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true

			part:Destroy()
		end
	end
end

local function makeOriginalInvisible(char)
	for _, part in ipairs(char:GetDescendants()) do
		if part:IsA("BasePart") then
			part.Transparency = 1
			part.CanCollide = false
		end
	end
end

-- Function to calculate explosion direction and add a combined impulse (upward + towards explosion)
local function addExplosionImpulse(ragdoll, impulseForce, explosionPosition)
	for _, part in ipairs(ragdoll:GetDescendants()) do
		if part:IsA("BasePart") then
			-- Calculate the direction from the part to the explosion position (corrected vector)
			local direction = (explosionPosition - part.Position).unit  -- Vector pointing from the part to the explosion

			-- Create an upward force vector (increased upward force)
			local upwardForce = Vector3.new(0, 1, 0) * (impulseForce * 1.2)  -- Increased upward force to make it fly stronger

			-- Combine the horizontal directional force and the stronger vertical upward force
			local combinedForce = direction * impulseForce * 0.3 + upwardForce  -- Adjusted horizontal force ratio

			-- Apply the combined force to the part
			part:ApplyImpulse(combinedForce)
		end
	end
end

-- Function to handle the ragdoll process when a player dies
local function handleDeath(char, explosionPosition)
	char.Archivable = true
	local dChar = char:Clone()
	char.Archivable = false

	local humanoidRootPart = dChar:FindFirstChild("HumanoidRootPart")
	if humanoidRootPart then
		humanoidRootPart.Anchored = false
		humanoidRootPart:Destroy()
	end

	if dChar then
		dChar.Parent = workspace
		dChar:SetPrimaryPartCFrame(char:GetPrimaryPartCFrame())

		for _, part in ipairs(dChar:GetDescendants()) do
			if part:IsA("BasePart") then
				part.CanCollide = true
				part.Anchored = false
				part.Transparency = 0
			end
		end

		local humanoid = dChar:FindFirstChildOfClass("Humanoid")
		if humanoid then
			humanoid.Health = 0
			humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
			humanoid:ChangeState(Enum.HumanoidStateType.Dead)
		end

		makeRagDoll(dChar)

		-- Add explosion impulse to the ragdoll
		addExplosionImpulse(dChar, 200, explosionPosition)  -- Adjust impulse force as needed (200 is a moderate value)

		-- 100% chance to rip off an arm from the ragdoll
		local arm = math.random(1, 2) == 1 and dChar:FindFirstChild("Left Arm") or dChar:FindFirstChild("Right Arm")
		if arm then
			-- Handle the Left Shoulder Attachment if the arm is the LeftArm
			if arm.Name == "Left Arm" then
				local leftshoulderAttachment = arm:FindFirstChild("LeftShoulderAttachment")
				if leftshoulderAttachment then
					leftshoulderAttachment:Destroy()  -- Disconnect the LeftShoulderAttachment
				end
			end

			-- Handle the Right Shoulder Attachment if the arm is the RightArm
			if arm.Name == "Right Arm" then
				local rightshoulderAttachment = arm:FindFirstChild("RightShoulderAttachment")
				if rightshoulderAttachment then
					rightshoulderAttachment:Destroy()  -- Disconnect the RightShoulderAttachment
				end
			end

			-- Detach and remove the arm from the ragdoll
			arm:Destroy()
			print("Arm ripped off from the ragdoll!")
		end

		debris:AddItem(dChar, CORPSE_LIFETIME)
	else
		warn("Failed to clone character!")
	end

	makeOriginalInvisible(char)
end

-- Connect to player death event
players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local humanoid = char:WaitForChild("Humanoid")
		humanoid.BreakJointsOnDeath = false
		humanoid.Died:Connect(function()
			print("Player Has Died!", player.Name)

			-- Define the explosion position (could be any position in the world)
			local explosionPosition = Vector3.new(0, 10, 0)  -- Example explosion location at (0, 10, 0)

			-- Handle the death and ragdoll with explosion
			handleDeath(char, explosionPosition)
		end)
	end)
end)