Adding a ragdoll to this clone script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    adding a ragdoll to the cloned character after it has died

  2. What is the issue? Include screenshots / videos if possible!
    it doesn’t ragdoll after death, i even added the ragdoll into the script

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i havent tried anything yet.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

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

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

-- Function to create a ragdoll for R6 characters
local function makeRagDoll(doll)
	-- Iterate through all parts of the character and replace Motor6D joints with BallSocketConstraint
	for _, part in ipairs(doll:GetDescendants()) do
		if part:IsA("Motor6D") then
			-- Create a new BallSocketConstraint
			local socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")

			-- Attach the constraint to the parts
			a1.Parent = part.Part0
			a2.Parent = part.Part1
			socket.Parent = part.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2

			-- Set attachment positions for the constraint based on the Motor6D joint's CFrame
			a1.CFrame = part.C0
			a2.CFrame = part.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true

			-- Destroy the original Motor6D joint to prevent conflict with the BallSocketConstraint
			part:Destroy()
		end
	end
end

-- Function to make the original character's parts invisible and non-collidable
local function makeOriginalInvisible(char)
	-- Make the original character's body parts invisible and non-collidable
	for _, part in ipairs(char:GetDescendants()) do
		if part:IsA("BasePart") then
			part.Transparency = 1
			part.CanCollide = false
		end
	end

	-- Ensure HumanoidRootPart is also invisible and non-collidable
	local humanoidRootPart = char:FindFirstChild("HumanoidRootPart")
	if humanoidRootPart then
		humanoidRootPart.Transparency = 1
		humanoidRootPart.CanCollide = false
	end
end

-- Function to handle the ragdoll process when a player dies
local function handleDeath(char)
	-- Clone the character to preserve its appearance, but DO NOT clone the HumanoidRootPart
	char.Archivable = true
	local dChar = char:Clone()
	char.Archivable = false

	-- Remove HumanoidRootPart from the cloned ragdoll
	local humanoidRootPart = dChar:FindFirstChild("HumanoidRootPart")
	if humanoidRootPart then
		humanoidRootPart:Destroy()
	end

	if dChar then
		-- Position the ragdoll clone at the same location as the original character
		dChar.Parent = workspace
		dChar:SetPrimaryPartCFrame(char:GetPrimaryPartCFrame())

		-- Make the ragdoll clone visible, non-anchored, and non-collidable
		for _, part in ipairs(dChar:GetDescendants()) do
			if part:IsA("BasePart") then
				part.CanCollide = true
				part.Anchored = false
				part.Transparency = 0 -- Make sure the ragdoll is visible
			end
		end

		-- Destroy the humanoid to stop the ragdoll from interacting with the game
		local humanoid = dChar:FindFirstChildOfClass("Humanoid")
		if humanoid then
			humanoid:Destroy()
		end

		-- Apply ragdoll physics to the clone
		makeRagDoll(dChar)

		-- Add ragdoll to Debris service for automatic cleanup
		debris:AddItem(dChar, CORPSE_LIFETIME)
	else
		warn("Failed to clone character!")
	end

	-- Make the original character invisible
	makeOriginalInvisible(char)
end

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

i made soke comments for you guys to know what that does or what it is.
Thanks for reading!
script is in serverscriptservice and its rig is R6

i commented out line 69 and turned on BreakJointsOnDeath and it worked fine

did it ragdoll? if so then i will check it out

yes it did
image

alright thanks for finding the solution!

sorry, you commented out line 69 and then turned on breakjointsondeath? if so wheres the line that i wrote it OR do i have to rewrite it after line 69

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