On death, I am running a ragdoll script which works great. I am trying to keep the ragdoll when the player leaves, and the clothings. But, as you might expect with HUMANOIDS… there is an issue.
Whenever the player leaves, the ragdoll goes into this odd state. The exact same state found in this post. Which was given no solution, of course. The state is also entered if the player leaves but does not die.
This is what the main part of the script looks like. It is very hacky, and there are many things in there I was just trying and did not work.
function RagDoll(character)
if character:FindFirstChild("HumanoidRootPart") then
local humanoid = character.Humanoid
local rig = humanoid.RigType
local root = character.HumanoidRootPart
root.Name = "HRPlol"
root.Anchored = true
root.CanCollide = false
--Ragdoll stuff
end
character.HRPlol.CollisionGroupId = math.random(100,1000)
end
local isDeadRan = false
player.CharacterRemoving:Connect(function(newChar)
newChar.Archivable = true
if isDeadRan == false then
newChar:BreakJoints()
RagDoll(newChar)
end
local t = newChar:Clone()
t.Humanoid.Health = 0
t.Name = "Dead"..t.Name
t.Parent = workspace
for i,v in pairs(t:GetDescendants())do
if v:IsA("Script") or v:IsA("LocalScript") or v:IsA("Motor") or v:IsA("Motor6D") or v:IsA("VelocityMotor") then
v:Destroy()
else
if v:IsA("BasePart") then
v.CanCollide = true
end
end
end
t.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
t.Humanoid.RigType = Enum.HumanoidRigType.R6
end)
humanoid.Died:Connect(function()
isDeadRan = true
RagDoll(character)
end)
Speaking of things that did not work. Here is everything I’ve tried, that has failed, and produced no different result: Changing state to Physics in different areas of the script and then doing it repeatedly in a while loop, Changing HRP name, Changing humanoid to a R6 model, changing it back after a little. anchoring the hrp, moving the hrp to a different collision group, changing the model name, killing the humanoid, platform standing the humanoid, duplicating the character and parenting it to workspace, deleting the HRP, and probably some other things, but its been 6 months since this problem came along.
Will the humanoid masters, wherever you may be, please… help me.
so i tried experimenting with your code and i found a problem that might not be the problem you described in the op. i turned on “Are Owners Shown” in studio settings to see if network replication is the problem, and it does seem to affect it
when the player leaves, the ragdoll is created and everything, but when the other player gets network ownership of the dead player’s body for some reason the motor6d’s are rebuilt, even though the server sees something completely different. i have no idea how this could be happening
Interesting. Thank you for experimenting. I’m going to use this and see if I can come up with some hacky solution now. I will post when I find anything helpful.
I took a while because I was unable to start local servers. Anyway, I used what you discovered to make a test, and it provided great results.
The new code looks like this. What changed was setting the network owner to the server. Apparenty you can only do this on unanchored parts, and the name check for hrp didnt work, so i lazily wrapped it in a pcall, lol.
player.CharacterRemoving:Connect(function(newChar)
newChar.Archivable = true
local t = newChar:Clone()
newChar.Archivable = false
t.Parent = workspace
t.Name = "Dead"..t.Name
for i,v in pairs(t:GetDescendants())do
if v:IsA("Script") or v:IsA("LocalScript") or v:IsA("Motor") or v:IsA("Motor6D") or v:IsA("VelocityMotor") then
v:Destroy()
else
if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
v.CanCollide = true
pcall(function()
v:SetNetworkOwner()
end)
end
end
end
if isDeadRan == false then
t:BreakJoints()
RagDoll(t)
end
end)
humanoid.Died:Connect(function()
isDeadRan = true
RagDoll(character)
end)
I have only tested it on a local server with one player, but I assume it would work with more.
It is not perfect yet, though, for it resets the ragdoll to the location of the HRP and then drops it. @infranova I also tried setting network owner to server right on death. But this was in combination with the other network ownership call, both provided the same results, I know we are very close.
i got it! it’s not the humanoid that’s causing the problems; it’s the humanoidrootpart! by deleting it from the corpse, these weird problems stop, without needing to mess with network ownership
here’s what i got in code (server script function connected to CharacterRemoving)
function createCorpse(oldChar)
oldChar.Archivable = true
local deadChar = oldChar:Clone()
oldChar.Archivable = false
deadChar.Name = deadChar.Name.."'s corpse"
for _, desc in ipairs(deadChar:GetDescendants())do
if desc:IsA("Script") or desc:IsA("LocalScript") then
desc:Destroy()
end
end
local deadHRP = deadChar.HumanoidRootPart
local deadHum = deadChar.Humanoid
deadHRP:Destroy()
deadChar.Parent = workspace
toggleRagdoll(deadChar, true)
deadHum:ChangeState(Enum.HumanoidStateType.Physics)
end
to handle player death, i would just connect the humanoid Died event to your ragdoll function and everything should still keep working, at least to my tests
Unfortunately, the provided solution only worked in a small environment. Once there were any more than 2 players, the bug continued with no difference.
function createCorpse(oldChar)
oldChar.Archivable = true
local deadChar = oldChar:Clone()
oldChar.Archivable = false
deadChar.Name = deadChar.Name.."'s corpse"
for _, desc in ipairs(deadChar:GetDescendants())do
if desc:IsA("Script") or desc:IsA("LocalScript") then
desc:Destroy()
end
end
local deadHRP = deadChar.HumanoidRootPart
local deadHum = deadChar.Humanoid
local deadHead = deadChar.Head
deadHRP:Destroy()
deadChar.Parent = workspace
toggleRagdoll(deadChar, true)
--this is the new line
deadHead:GetRootPart():SetNetworkOwner(nil)
deadHum:ChangeState(Enum.HumanoidStateType.Dead)
end
You also seemed to have changed the state type to dead instead of physics, is this intentional? Should you change it to physics? Will it work when the player dies first then leaves? Will it work With say 5 players?
It seems to work with 2 players so I’m going to assume it just works. I will be back if it does not, until then a question on the web that has gone unanswered for years, is now settled!