For some reasons the HumanoidRootPart of the npc disappears It is suppose to ragdoll him and after put him normal and upright sort of like a knockback ragdoll, if there is another way to do that without getting this much trouble or a better way please let me know.
for your information, this script is inside the npc and it is a script which means it is server sided.
local humanoid = script.Parent:WaitForChild("Humanoid")
humanoid.RequiresNeck = false
local defaultPos = script.Parent.HumanoidRootPart.Position
humanoid.Died:Connect(function()
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
for i,v in pairs(script.Parent:GetDescendants()) do
if v:IsA("Motor6D") then
v.Enabled = false
--v.Part0 = nil
elseif v:IsA("WeldConstraint") then
v.Enabled = true
end
end
for index,joint in pairs(script.Parent:GetDescendants()) do
if joint:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment")
local a2 = Instance.new("Attachment")
a1.Parent = joint.Part0
a2.Parent = joint.Part1
socket.Parent = joint.Parent
socket.Attachment0 = a1
socket.Attachment1 = a2
a1.CFrame = joint.C0
a2.CFrame = joint.C1
end
end
task.wait(2)
humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
for i,v in pairs(script.Parent:GetDescendants()) do
if v:IsA("Motor6D") then
v.Enabled = true
elseif v:IsA("WeldConstraint") then
v.Enabled = false
end
end
local bodyGyro = Instance.new("BodyGyro")
local npcHumanoidRootPart = script.Parent.HumanoidRootPart
bodyGyro.Parent = npcHumanoidRootPart
pcall(function()
print("reached end")
npcHumanoidRootPart.BodyGyro.CFrame = CFrame.new(defaultPos.Position, Vector3.new(npcHumanoidRootPart.Position.X, defaultPos.Position.Y, npcHumanoidRootPart.Position.Z))
end)
end)