I’m currently trying to make a script where a corpse would spawn where the player is after the player dies. The script is supposed to clone the player’s character and ragdoll the clone when the player dies.
This is a ServerScript in ServerScriptStorage:
function RagdollCharacter(character)
character.Humanoid:ChangeState(Enum.HumanoidStateType.Dead)
local d = character:GetDescendants()
for i=1,#d do
local desc = d[i]
if desc:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local part0 = desc.Part0
local joint_name = desc.Name
local attachment0 = desc.Parent:FindFirstChild(joint_name.."Attachment") or desc.Parent:FindFirstChild(joint_name.."RigAttachment")
local attachment1 = part0:FindFirstChild(joint_name.."Attachment") or part0:FindFirstChild(joint_name.."RigAttachment")
if attachment0 and attachment1 then
socket.Attachment0, socket.Attachment1 = attachment0, attachment1
socket.Parent = desc.Parent
desc:Destroy()
end
end
end
end
function ClonePlayerCharacter(character)
character.Archivable = true
local corpse = character:Clone()
corpse.Parent = game.Workspace
return corpse
end
function GenerateCorpseByCloningPlayerCharacter(character)
local corpse = ClonePlayerCharacter(character)
print(corpse.Name)
RagdollCharacter(corpse)
end
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(character)
character.Humanoid.BreakJointsOnDeath = false
character.Humanoid.Died:Connect(function()
GenerateCorpseByCloningPlayerCharacter(character)
end)
end)
end)
Unfortunately, the clone won’t ragdoll unless I switch the mode to server.
Notice how the corpse is just rigid after the player dies but when the roblox studios mode is switched to server the corpse becomes ragdolled. How do I make the ragdoll be seen locally also?
Update:
The part of the script that ragdolls the corpse does it by deleting Motor6Ds and adding ball sockets in its place.
I just found out that the Motor6Ds are not deleting locally and are only deleting on the server’s side which is why the corpse is only ragdolling on the server-side. (This might be helpful info but I’m still not sure how to use this info to solve the problem)