Ragdoll glitching out on NPCs but working fine for players

Currently have a ragdoll system that works fine for players, but when I use it on the server for NPC’s, it seems to break half the time.

GIFS

https://gyazo.com/b97cf2aad0fd3e408e12cb01c3ae87cd
As you can see here, whenever the NPC ragdolls, it hovers in place for some reason, but when I activate the ragdoll on the player (which is using the exact same code) it works as intended.

However, sometimes it actually does work, and I was able to snag a quick gif of it.
https://gyazo.com/78b513a36988f1ac0135a0f360e067bf

I suspect it as something to do with the BodyVelocity I add to the character’s HumanoidRootPart just to push the it back a bit, however it only applies a force for 0.125 seconds so I don’t understand what the issue is. Perhaps some other HumanoidState is being triggered during that small window? No idea.

Code Snippet
Entity.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
Entity.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)
Entity.Humanoid:SetStateEnabled(Enum.HumanoidStateType.RunningNoPhysics, false)
Entity.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
Entity.Humanoid.WalkSpeed = 0
Entity.Humanoid.JumpHeight = 0

for _, Child in ipairs(Entity.Torso:GetChildren()) do
	if Child:IsA("Motor6D") then

		local BallSocket = Instance.new("BallSocketConstraint")
		BallSocket.Name = Child.Name
		local Attachment0 = Instance.new("Attachment")
		local Attachment1 = Instance.new("Attachment")

		Attachment0.Parent = Child.Part0
		Attachment1.Parent = Child.Part1

		BallSocket.Attachment0 = Attachment0
		BallSocket.Attachment1 = Attachment1
		BallSocket.Parent = Child.Parent

		Attachment0.CFrame = Child.C0
		Attachment1.CFrame = Child.C1
		Debris:AddItem(Attachment0, 3)
		Debris:AddItem(Attachment1, 3)

		BallSocket.LimitsEnabled = true
		BallSocket.TwistLimitsEnabled = true

		Child.Enabled = false
	end
end

local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.MaxForce = Vector3.new(20000, 20000, 20000)
BodyVelocity.Velocity = Entity.HumanoidRootPart.CFrame.LookVector * -30
BodyVelocity.Parent = Entity.HumanoidRootPart
Debris:AddItem(BodyVelocity, 0.125)

I haven’t included the code that resets the Character back to it’s previous states and all that, but I assure you that it’s there and working. If you do need it for further debugging, I’ll edit the code above and add it.

1 Like

I’ve experienced this before.

Try this:

Entity.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
Entity.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)
Entity.Humanoid:SetStateEnabled(Enum.HumanoidStateType.RunningNoPhysics, false)
Entity.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
Entity.Humanoid.WalkSpeed = 0
Entity.Humanoid.JumpHeight = 0

for _, Child in ipairs(Entity.Torso:GetChildren()) do
	if Child:IsA("Motor6D") then

		local BallSocket = Instance.new("BallSocketConstraint")
		BallSocket.Name = Child.Name
		local Attachment0 = Instance.new("Attachment")
		local Attachment1 = Instance.new("Attachment")

		Attachment0.Parent = Child.Part0
		Attachment1.Parent = Child.Part1

		BallSocket.Attachment0 = Attachment0
		BallSocket.Attachment1 = Attachment1
		BallSocket.Parent = Child.Parent

		Attachment0.CFrame = Child.C0
		Attachment1.CFrame = Child.C1
		Debris:AddItem(Attachment0, 3)
		Debris:AddItem(Attachment1, 3)

		BallSocket.LimitsEnabled = true
		BallSocket.TwistLimitsEnabled = true

		Child.Enabled = false
	end
end

local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.MaxForce = Vector3.new(20000, 20000, 20000)
BodyVelocity.Velocity = Entity.HumanoidRootPart.CFrame.LookVector * -30
BodyVelocity.Parent = Entity.HumanoidRootPart

for _,v in ipairs(Entity:GetChildren()) do
v.Anchored = false
end
Debris:AddItem(BodyVelocity, 0.125)
1 Like

Hm, didn’t seem to work. Although the NPC only hovers and glitches out after a couple successful ragdolls.

HumanoidRootPart has a Motor6D named “Root Hip”. Maybe you can try disabling that too?

Yea didn’t really seem to change anything, I suspect it has something to do with the Server not being able to change/toggle the HumanoidStateTypes.

I was able to solve the problem,

All you had to do is set the NetworkOwnership of the NPC’s HumanoidRootPart to the server(nil).
For players, this shouldn’t be an issue since you should be handling the ragdoll on the client anyways.