I am trying to make a script that, when the humanoid of an NPC dies, the NPC ragdolls. Simple right? I guess not. I tried an open source ragdoll module, which the NPC just flips around and flies off. Then I tried to code it myself, and it didn’t go too well. Here’s my code:
local human = script.Parent.Humanoid
local limbs = script.Parent:GetChildren()
human.Died:Connect(function()
print("died")
human:Destroy()
local newlimbtable = human:GetChildren()
for i = 1, #newlimbtable do
local newlimb = newlimbtable[i]
local jointstable = newlimb:GetChildren()
for i = 1, #jointstable do
local oldjoint = newlimb:FindFirstChild(jointstable[newlimb.Name])
local newjoint = Instance.new("BallSocketConstraint")
newjoint.Part0 = oldjoint.Part0
newjoint.Part1 = oldjoint.Part1
newjoint.C0.Position = oldjoint.C0.Position
newjoint.C0.Orientation = oldjoint.C0.Orientation
newjoint.C1.Position = oldjoint.C1.Position
newjoint.C1.Orientation = oldjoint.C1.Orientation
newjoint.Name = oldjoint.Name
oldjoint:Destroy()
end
end
end)
The NPC just turns blocky and falls over as one. The limbs don’t move at all.
