Hi! I am trying to make the character ragdoll when dying. However the character ragdolls slightly and just freezes. Even when the character respawns and I reset, the result is the same.
Heres the code in LocalScript, which is stored in StarterCharacterScripts
local char = script.Parent
script.Parent.Humanoid.Died:Once(function()
char.HumanoidRootPart.AssemblyLinearVelocity = char.HumanoidRootPart.CFrame.LookVector * -60
for i, v : Instance in pairs(char:GetDescendants()) do
if v:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment")
local a2 = Instance.new("Attachment")
a1.Parent = v.Part0
a2.Parent = v.Part1
socket.Parent = v.Parent
socket.Attachment0 = a1
socket.Attachment1 = a2
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
socket.MaxFrictionTorque = 20
a1.CFrame = v.C0
a2.CFrame = v.C1
v.Parent.Massless = true
v:Destroy()
end
end
end)
Heres the code in Script, which is stored in ServerScriptService
The MaxFrictionTorque property basically applies how much resistance to torque/rotation of the ballsocketconstraint to keep them aligned so it makes it appear the character ragdoll freezes when in reality your resisting anymore rotation for the ragdoll.
I don’t really think that this is the problem, but just in case, try removing the line that makes the parents Massless. Maybe a mismatch with the assembly root psrt could be causing an issue.
Oh okay, apparently the server gains ownership of the physics once the player dies.
Maybe you could manually set the network owner back to the client, but I’m not sure. Check out the thread tho, maybe you can find a better answer there.
yeah networkownership works so use a script instead of a local script for the ragdoll and setnetworkowner of all unachored parts of the character to the player of its character it appears smoother:
local char = script.Parent
local player=game.Players:GetPlayerFromCharacter(humanoid.Parent)
script.Parent.Humanoid.Died:Once(function()
char.HumanoidRootPart.AssemblyLinearVelocity = char.HumanoidRootPart.CFrame.LookVector * -60
for i, v : Instance in pairs(char:GetDescendants()) do
if v:IsA(“Motor6D”) then
local socket = Instance.new(“BallSocketConstraint”)
local a1 = Instance.new(“Attachment”)
local a2 = Instance.new(“Attachment”)
a1.Parent = v.Part0
a2.Parent = v.Part1
socket.Parent = v.Parent
socket.Attachment0 = a1
socket.Attachment1 = a2
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
socket.MaxFrictionTorque = 20
a1.CFrame = v.C0
a2.CFrame = v.C1
v.Parent.Massless = true
v:Destroy()
end
if v:IsA("BasePart") and not v.Anchored then
warn("y")
v:SetNetworkOwner(player)
end
end
local char = script.Parent
local player=game.Players:GetPlayerFromCharacter(humanoid.Parent)
script.Parent.Humanoid.Died:Once(function()
char.HumanoidRootPart.AssemblyLinearVelocity = char.HumanoidRootPart.CFrame.LookVector * -60
for i, v : Instance in pairs(char:GetDescendants()) do
if v:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment")
local a2 = Instance.new("Attachment")
a1.Parent = v.Part0
a2.Parent = v.Part1
socket.Parent = v.Parent
socket.Attachment0 = a1
socket.Attachment1 = a2
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
socket.MaxFrictionTorque = 20
a1.CFrame = v.C0
a2.CFrame = v.C1
v.Parent.Massless = true
v:Destroy()
end
if v:IsA("BasePart") and not v.Anchored then
warn("y")
v:SetNetworkOwner(player)
end
end
end)