Im making a ragdoll system but for some reason the second time they ragdoll something wierd happens when they ragdoll a second time:
Thier torso stands up when they ragdoll a second time. I have no idea why this happens . Heres my code:
chr.Humanoid.RequiresNeck = false
chr.Humanoid.PlatformStand = true
chr.Humanoid.AutoRotate = false
local objects = {}
local toenable = {}
for i,v:Motor6D in chr:GetDescendants() do
if v:IsA("Motor6D") and v.Name ~= "RootJoint" then
if v.Enabled == false then return end
v.Enabled = false
local b = Instance.new("BallSocketConstraint",v.Parent)
local newattach1 = Instance.new("Attachment",v.Part0)
local newattach2 = Instance.new("Attachment",v.Part1)
if v.Part1.CanCollide == false then
local hitbox = Instance.new("Part")
local weld = Instance.new("Weld")
weld.Part0 = v.Part1
weld.Part1 = hitbox
hitbox.Size = v.Part1.Size / 1.7
hitbox.Transparency = 1
weld.Parent = hitbox
hitbox.Parent = v.Part1
table.insert(objects,weld)
table.insert(objects,hitbox)
game.Debris:AddItem(weld,ragdolltime + 0.1)
game.Debris:AddItem(hitbox,ragdolltime + 0.1)
end
newattach1.Name = "1"
newattach2.Name = "2"
newattach1.CFrame = v.C0
newattach2.CFrame = v.C1
b.Radius = 0.15
b.LimitsEnabled = true
b.TwistLimitsEnabled = false
b.MaxFrictionTorque = 0
b.Restitution = 100
b.UpperAngle = 90
b.TwistLowerAngle = -45
b.TwistUpperAngle = 45
if v.Name == "Neck" then
b.TwistLimitsEnabled = true
b.UpperAngle = 45
b.TwistLowerAngle = -70
b.TwistUpperAngle = 70
end
b.Attachment0 = newattach1
b.Attachment1 = newattach2
table.insert(objects,b)
table.insert(objects,newattach1)
table.insert(objects,newattach2)
table.insert(toenable,v)
game.Debris:AddItem(newattach1,ragdolltime + 0.1)
game.Debris:AddItem(newattach2,ragdolltime + 0.1)
game.Debris:AddItem(b,ragdolltime + 0.1)
end
end
task.wait(ragdolltime)
for i,v in pairs(objects) do
v:Destroy()
end
for i,v in pairs(toenable) do
v.Enabled = true
end
chr.Humanoid.PlatformStand = false
chr.Humanoid.AutoRotate = true
chr.HumanoidRootPart.Orientation = Vector3.new(0,chr.HumanoidRootPart.Orientation.Y,0)
chr.HumanoidRootPart.CFrame *= CFrame.new(0,3,0)