Ragdoll script issue

Hey all, I’ve been doing my own ragdoll script for my game, and I have this issue: (See the video)
https://gyazo.com/282798f1b2e50afa01e27adee50ae695

My current script in Server Script Service:

local Debris = game:GetService("Debris")


game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char:WaitForChild("Humanoid").BreakJointsOnDeath = false
		char.Humanoid.Died:Connect(function()
			
			char.Archivable = true
			
			local corpse = char:Clone()
			corpse.Name = char.Name.." corpse"
			
			if corpse:FindFirstChild("Humanoid") then
				local hum = corpse:FindFirstChild("Humanoid")
				hum:ChangeState(Enum.HumanoidStateType.Ragdoll)
				hum.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
				hum.MaxHealth = 0
				hum.Health = 0
				hum.PlatformStand = false
			end
			
			corpse.HumanoidRootPart:Destroy()	
			
			for _, v in pairs(corpse:GetDescendants{}) do
				if v:isA("Motor6D") then
					
					local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
					a0.CFrame = v.C0
					a1.CFrame = v.C1
					a0.Parent = v.Part0
					a1.Parent = v.Part1

					local b = Instance.new("BallSocketConstraint")
					b.Attachment0 = a0
					b.Attachment1 = a1
					b.Parent = v.Part0

					v:Destroy()
					
				end
				local part = corpse.Head
				local bf = Instance.new("BodyForce")
				--bf.Force = Vector3.new(0,0,-10)
				local a = math.random(-4,4)
				if a >= -4 and a <= 0 then
					bf.Force = Vector3.new(math.random(-10,15), 0, -10)
				elseif a >= 0 and a <=4 then
					bf.Force = Vector3.new(math.random(-15,10), 0, 10)
				end
				bf.Parent = part
			end
			corpse.Parent = workspace
			char.Parent = nil
			Debris:AddItem(corpse, 60)
			end)
		end)
	end)

Any help would be appreciated, I spent a lot of time trying to figure out how to fix it, and still haven’t.

EDIT: I also tried to change humanoid state to Ragdoll, but it didn’t change a lot.

1 Like

Hi!

I’m a little bit in a hurry right now and will edit this post as soon as I can when I find the solution, but I noticed that the ragdoll falls as soon as you disable the main BallSocketConstraint. At that moment ragdoll’s head falls off and corpse behaves as expected, until you enable BallSocketConstraint back again: the head travels back to the corpse, which still stays on the same spot as expected. This is probably not the solution, although we can be quite sure that the problem persists either in UpperTorso or in humanoid’s state.

EDIT, NOW WORKING
@Gleb3381 so you mentioned that you have already tried setting humanoid’s state type to ragdoll. I am not sure why, but the corpse’s state was still set to running at the end of the code, probably because of the movement, so that’s why it didn’t fall. If you add this statement at the end of the code, the body falls:

corpse.Parent = workspace
char.Parent = nil
corpse.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)  -- new line at the end
print(corpse.Humanoid:GetState())  -- testing purpose
Debris:AddItem(corpse, 60)

Whether you do this or not, corpse’s state for some reason always changes back to running (even when lying on the ground). Using the added statement, it just changes the state for an extremely short time, but enough for it to not float anymore.

Roblox - DevForum - Ragdoll - screenshot.PNG

It seems that the torso is being anchored somehow. Try unanchoring the torso on death.

Cheers, thank you! This worked, and now I can waste my time on scripting other scripts. Sorry for a late reply!

1 Like