Weird ragdoll movement

Hello, I put together with AI code together for ragdoll but it’s all weird. Instead of normal ragdoll, all the limbs beside torso clips through ground and head moves in random direction at the speed of light. I’m trying to make it like a normal ragdoll when you just fall without any limb clipping through anything and a bit realistic so the limbs don’t bend unnaturally. I also encounter rare bug when the player gets up, they will just stand on their head and the only way to get unstuck is to reset.
I want to make this work for R6, I already tried R15 too.

The code:

local ragdoll = {}
ragdoll.Constraints = {}

function ragdoll.Start(character)
	if character.Ragdoll.Value then return end
	character.Ragdoll.Value = true

	local physicsService = game:GetService("PhysicsService")
	local collisionGroupName = "RagdollCollisionGroup"

	if not physicsService:IsCollisionGroupRegistered(collisionGroupName) then
		physicsService:RegisterCollisionGroup(collisionGroupName)
	end

	physicsService:CollisionGroupSetCollidable(collisionGroupName, collisionGroupName, true)
	physicsService:CollisionGroupSetCollidable(collisionGroupName, "Default", true)

	local torso = character:FindFirstChild("Torso")
	if torso then
		torso.CollisionGroup = collisionGroupName
		torso.Anchored = true
	end

	for _, joint in pairs(character:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local part0 = joint.Part0
			local part1 = joint.Part1
			local c0 = joint.C0
			local c1 = joint.C1

			local att0 = Instance.new("Attachment", part0)
			local att1 = Instance.new("Attachment", part1)
			att0.CFrame = c0
			att1.CFrame = c1

			local newConstraint

			if joint.Name == "Neck" or joint.Name == "Left Shoulder" or joint.Name == "Right Shoulder" then
				newConstraint = Instance.new("BallSocketConstraint")
				newConstraint.Attachment0 = att0
				newConstraint.Attachment1 = att1
				newConstraint.LimitsEnabled = true
				newConstraint.TwistLimitsEnabled = true
				newConstraint.UpperAngle = 45
			elseif joint.Name == "Left Hip" or joint.Name == "Right Hip" then
				newConstraint = Instance.new("HingeConstraint")
				newConstraint.Attachment0 = att0
				newConstraint.Attachment1 = att1
				newConstraint.LimitsEnabled = true
				newConstraint.LowerAngle = -30
				newConstraint.UpperAngle = 30
			else
				newConstraint = Instance.new("BallSocketConstraint")
				newConstraint.Attachment0 = att0
				newConstraint.Attachment1 = att1
				newConstraint.LimitsEnabled = true
				newConstraint.TwistLimitsEnabled = true
				newConstraint.UpperAngle = 30
			end

			if newConstraint then
				newConstraint.Parent = part0
				table.insert(ragdoll.Constraints, newConstraint)
			end

			joint.Enabled = false

			part0.CollisionGroup = collisionGroupName
			part1.CollisionGroup = collisionGroupName
			part0.CanCollide = true
			part1.CanCollide = true
		elseif joint:IsA("BasePart") then
			joint.CollisionGroup = collisionGroupName
			joint.CanCollide = true
		end
	end

	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = 0
		humanoid.JumpPower = 0
		humanoid.PlatformStand = true
		humanoid.AutoRotate = false
	end

	if torso then
		torso.Anchored = false
	end
end

function ragdoll.Stop(character)
	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.PlatformStand = false
	end

	for _, constraint in ipairs(ragdoll.Constraints) do
		if constraint then
			constraint:Destroy()
		end
	end
	ragdoll.Constraints = {}

	for _, joint in pairs(character:GetDescendants()) do
		if joint:IsA("Motor6D") then
			joint.Enabled = true
		end
	end

	character.Ragdoll.Value = false

	if humanoid then
		humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
		humanoid.WalkSpeed = 16
		humanoid.JumpPower = 50
		humanoid.AutoRotate = true
	end
end

return ragdoll

Hi there.

Instead of using AI to write code for you, I recommend looking at existing code from other people — see if you can find an open-source ragdoll module or a tutorial online.

Just make sure you’re always doing something yourself, as you’ll learn and improve, and also it will allow you to work further on the code, as you understand it yourself.

Hope this helps, even though it wasn’t the solution you were looking for.

4 Likes

It’s the only solution you can give, if they don’t know how to script in the slightest, you can’t explain the issue, they just won’t understand it.

2 Likes

Hello.

Thanks for suggesting this. I tried following tutorials but the codes never worked or were depracated.
It’s not like I don’t understand coding like @SharkRayMaster mentioned, I just don’t know how to make the ragdoll code and tutorials weren’t helping so I resorted to using AI for this specific code.
I will try to look for more tutorials in hope of 1 of them working but I would appreciate if you or someone else could at least take a look at the code and try to figure out why is the movement weird.

Thanks and have a nice day/night.

Hi there.

Often open-source code can be helpful. Check out for example Abrah_m's Ragdoll System V1 [Open-Sourced] - #3 by abrah_m

Open-source is code that is free for anyone to use and modify for any purpose.
Often it is maintained and updated, and the creators will answer your questions on the topic.

If you have any more questions, let me know!

Tutorials do help, you just need to find a good one that explains it correctly assuming you’re actually willing to learn. But using AI wont fix anything, it usually just gives you code and whenever you need to edit something or something breaks, you’re screwed since you won’t know how to fix it, like it happened here.

This is the tutorial I learnt from back then: How to Make ROBLOX Ragdolls: the BEST Way

As he mentions, if you wanna copy paste code, that’s the wrong video.

A rough idea is: Roblox characters have a lot of limbs which are joined together via Motor6Ds, and these motor6ds have properties with information of “the midpoint” between the parts, the “joint”.

You replace these Motor6Ds with BallSocketConstraints and Attachments

Then you’re just missing a way to stop the player humanoid from trying to get up, in your script you use PlatformStand, which is easy and works, but also messy, preferably you wanna set the humanoid state.