Need a guide to make A ragdoll script

  1. What do you want to achieve? I want to ragdoll an r6 npc when it dies

  2. **What is the issue? I just need a guide to what to do I can code it myself I just dont know how to do it

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? yes i did but i didnt find any good scripts at all.

It would be good to include whether is the NPC R6 or R15 character. There are differences when making a radgoll script, I belive.

Oh it’s an r6 but I dont know how ragdolling an npc works.

Okay.
I have never personally done ragrolling an NPC, but I have done a script, that ragdolls a player. I belive it will be the same system. I think there are already some topics talking about making a radgoll.

it should work the same since its a character too isnt it? Can you provide me the code if possible?

1 Like

Yes of course, I’m loading into studio.

1 Like

Okay,
This is the part of the script that makes player ragdoll once he dies.

Script
		local leftArm = char:WaitForChild("Left Arm")
		local rightArm = char:WaitForChild("Right Arm")
		
		local torso = char:WaitForChild("Torso")
		local humanoid = char:WaitForChild("Humanoid")
		humanoid.BreakJointsOnDeath = false
		
		local leftLeg = char:WaitForChild("Left Leg")
		local rightLeg = char:WaitForChild("Right Leg")
		
		--// ARMS \\--
		
		local lca = torso:WaitForChild("LeftCollarAttachment")
		local rca = torso:WaitForChild("RightCollarAttachment")
		
		local laAtt = Instance.new("Attachment", leftArm)
		laAtt.Orientation = Vector3.new(0, 0, 45)
		laAtt.Position = Vector3.new(.5, 1, 0)
		laAtt.Name = "Ragdoll"
		
		local raAtt = laAtt:Clone()
		raAtt.Orientation = Vector3.new(0, 0, -45)
		raAtt.Position = Vector3.new(-.5, 1, 0)
		raAtt.Parent = rightArm
		raAtt.Name = "Ragdoll"
		
		local laBall = Instance.new("BallSocketConstraint", leftArm)
		laBall.Name = "LeftArmRagdoll"
		laBall.Attachment0 = lca
		laBall.Attachment1 = laAtt
		laBall.LimitsEnabled = true
		
		local raBall = Instance.new("BallSocketConstraint", rightArm)
		raBall.Name = "RightArmRagdoll"
		raBall.Attachment0 = rca
		raBall.Attachment1 = raAtt
		raBall.LimitsEnabled = true
		
		--// LEGS \\--
		
		local leftLegAtt = Instance.new("Attachment", leftLeg)
		leftLegAtt.Name = "Ragdoll"
		leftLegAtt.Position = Vector3.new(0, 1, 0)
		
		local rightLegAtt = Instance.new("Attachment", rightLeg)
		rightLegAtt.Name = "Ragdoll"
		rightLegAtt.Position = Vector3.new(0, 1, 0)
		
		local torsoLeftLegAtt = Instance.new("Attachment", torso)
		torsoLeftLegAtt.Name = "TorsoLeftLegAtt"
		torsoLeftLegAtt.Position = Vector3.new(-.5, -1, 0)
		
		local torsoRightLegAtt = Instance.new("Attachment", torso)
		torsoRightLegAtt.Name = "TorsoRightLegAtt"
		torsoRightLegAtt.Position = Vector3.new(.5, -1, 0)
		
		local leftLegBall = Instance.new("BallSocketConstraint", leftLeg)
		leftLegBall.Name = "LeftLegRagdoll"
		leftLegBall.Attachment0 = torsoLeftLegAtt
		leftLegBall.Attachment1 = leftLegAtt
		
		local rightLegBall = Instance.new("BallSocketConstraint", rightLeg)
		rightLegBall.Name = "RightLegRagdoll"
		rightLegBall.Attachment0 = torsoRightLegAtt
		rightLegBall.Attachment1 = rightLegAtt
		
		humanoid.HealthChanged:Connect(function()
			if not char:FindFirstChild("Ragdolled") and humanoid.Health <= 40 then
				local ragdollValue = Instance.new("BoolValue", char)
				ragdollValue.Value = true
				ragdollValue.Name = "Ragdolled"
				
				humanoid.PlatformStand = true
				for i,v in pairs(torso:GetChildren()) do
					if v:IsA("Motor6D") and v.Name ~= "Neck" then
						v.Enabled = false
					end
				end
				
				local bv = Instance.new("BodyVelocity", torso)
				bv.Velocity = torso.CFrame.LookVector * -10
				game:GetService("Debris"):AddItem(bv, .1)
				
			--[[elseif humanoid.Health > 40 and char:FindFirstChild("Ragdolled") then
				game.ReplicatedStorage.Remotes.MakeBodypartsColliding:FireClient(plr)
				
				humanoid.PlatformStand = false
				char.Ragdolled:Destroy()
				for i,v in pairs(torso:GetChildren()) do
					if v:IsA("Motor6D") then
						v.Enabled = true
					end
				end]]
			end
		end)

Oh wow. Now when I look on the script I see it’s pretty messy, but I think you will be able to learn from it. The script was made for one game, so it works the player gets ragdolled once his health is lower than 40.
This is not the full script (but it isn’t missing much lines) as I want you to learn from this and eventually make your very own script (as it is better way how to learn scripting). There might be also some issues with the script, I haven’t tested it really much, but the main part works well.
The BodyVelocity makes player launch back a little bit, but I think there have been issues like when the player gets under 40 health while he is jumping then he starts flying away, so I don’t know if it will happen to you as well, but I trust you will be able to fix it if it would happen to you as well.

EDIT: The commented part was used to get the player back up, but I commented it out once we made another script to make the player up once he got healed.

EDIT2: Also you might need to make the BodyParts (Arms and Legs) collidable, as by default they aren’t and they would just go no-clip with the floor.

I hope this helped!
Have a nice day.

1 Like

ngl but I found a similar script of this before I was posting this topic.
Using the second parameter of instance.new() is bad as it can parent for like .04 or 0.4 seconds was it but i can modify this to my liking thanks

1 Like

Oh thank you letting me know that. I will definetly remind that when scripting!

There’s a better way that will work for R15 rig. Haven’t tested with R6 but should work.

local PS = game:GetService'PhysicsService'
local char = workspace.MyNPC
local Hum = char.Humanoid
Hum.BreakJointsOnDeath = false
Hum.RequiresNeck = false

for _,C in pairs(c:GetDescendants()) do
	if C:IsA("Motor6D")then
		local socket = Instance.new("BallSocketConstraint",C.Parent)
		local a0,a1 = Instance.new("Attachment"),Instance.new("Attachment")
		a0.Parent,a1.Parent = C.Part0,C.Part1
		socket.Attachment0,socket.Attachment1 = a0,a1
		a0.CFrame,a1.CFrame = C.c0,C.c1
		socket.LimitsEnabled = true -- remove for r6
		socket.TwistLimitsEnabled = true -- remove for r6
		socket.Enabled = false -- You don't need this line if you're ragdolling on death.
		C:Destroy() -- keep it only if ur ragdolling on death
	elseif C:IsA'BasePart' then -- You might not need this if you're doing it on death but I'd keep it.
		PS:SetPartCollisionGroup(C,"C")
		if C.Name == "HumanoidRootPart" then
			PS:SetPartCollisionGroup(C,"HRP")
        --prevents collisions with HumanoidRootPart. You'll need to make two collision groups one named "C" and another named "HRP". Turn off HRP/C and HRP/HRP collisions.
		end
	end
end
5 Likes

How would I modify it to work on r6 as this is a cleaner way of doing it?

In my opinion, you should use R15 rigs as they are much better and appealing to players. I just tested the same code with R6 rig, you will have to remove two limit enabled lines. Note: I tested on player not on NPC but that shouldn’t be the problem. Edited the code above.

[quote=“lagnis7859, post:10, topic:968062”]

socket.LimitsEnabled = true
		socket.TwistLimitsEnabled = true

[/quote]|

are you reffering to this?Thanks too

Yes, do you want NPCs to ragdoll on death or you want them to ragdoll them before dying also?

nope on death is enough.But thank you dude and also the reason im using r6 is because of a problem im having on my r15 custom rig

Hey there’s seems to be a little hiccup in your code and uh you forgot to disabled the motor6d of each parts.

Yeah, I forgot to edit that. I made this code for ragdolling players while they still live. So, disabling/enabling parts were in another script. Edited the script above.

1 Like