You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
whenever the player dies, his clothes get cloned and accessories with the body
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
none
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)
for _, part in ipairs(char:GetDescendants()) do
if part:IsA("BasePart") then
part.Transparency = 1
part.CanCollide = false
end
end
end
-- Function to handle the ragdoll process when a player dies
local function handleDeath(char)
-- Clone the character to preserve its appearance
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.Anchored = false -- Ensure HRP is unanchored
humanoidRootPart:Destroy() -- Remove to avoid conflicts
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 and apply physics
for _, part in ipairs(dChar:GetDescendants()) do
if part:IsA("BasePart") then
part.CanCollide = true
part.Anchored = false -- Ensure parts are unanchored
part.Transparency = 0 -- Make 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() -- Prevent health regen and other mechanics
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.BreakJointsOnDeath = false -- Prevent automatic joint breaking
humanoid.Died:Connect(function()
print("Player Has Died!", player.Name)
handleDeath(char)
end)
end)
end)
Hi! It looks like you’re trying to make whenever the player dies, it makes you ragdoll.
If you want to continue with this script, I guess the error is deleting the Humanoid, because the Humanoid is responsible for controlling the accessories and clothing you wear and make them appear.
If you want something simpler, you could just do when the player dies (or it joins and character loads), set the Humanoid property “BreakJointsOnDeath” to false and ragdoll the dead character. It will work the same!
yea, the thing is the character gets CLONED after he dies, and stays in the workspace for 120 seconds, whenever i keep the humanoid in it just breaks on me, or it gets anchored, could you give me a script sample so i could try it out? Might just be my mistakes…
I guess it is working. I just changed the Humanoid part. When the player dies, it sometimes remains standing, but I think in game, with character moving, jumping, etc, this won’t happen.
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)
for _, part in ipairs(char:GetDescendants()) do
if part:IsA("BasePart") then
part.Transparency = 1
part.CanCollide = false
end
end
end
-- Function to handle the ragdoll process when a player dies
local function handleDeath(char)
-- Clone the character to preserve its appearance
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.Anchored = false -- Ensure HRP is unanchored
humanoidRootPart:Destroy() -- Remove to avoid conflicts
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 and apply physics
for _, part in ipairs(dChar:GetDescendants()) do
if part:IsA("BasePart") then
part.CanCollide = true
part.Anchored = false -- Ensure parts are unanchored
part.Transparency = 0 -- Make visible
end
end
-- Destroy the humanoid to stop the ragdoll from interacting with the game
--[CHANGES:]
local humanoid = dChar:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Health = 0 -- sets health to 0
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None -- makes no one be able to see his life or name
humanoid:ChangeState(Enum.HumanoidStateType.Dead) -- makes the player looks like dead for server
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.BreakJointsOnDeath = false -- Prevent automatic joint breaking
humanoid.Died:Connect(function()
print("Player Has Died!", player.Name)
handleDeath(char)
end)
end)
end)