Ragdoll not working

robloxapp-20241107-2328206.wmv (333.1 KB)

Code im using:

local function applyRagdoll(character)
	character.Humanoid.WalkSpeed = 0
	character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	wait(0.1)
	character.HumanoidRootPart.AssemblyLinearVelocity = Vector3.new(0, -10, 0)
	character.Humanoid.AutoRotate = false
	local d = character:GetDescendants()
	for i = 1, #d do
		local desc = d[i]
		if desc.ClassName == "Motor6D" then

			local socket = Instance.new("BallSocketConstraint")
			local part0 = desc.Part0
			local part1 = desc.Part1
			local joint_name = desc.Name


			local attachment0 = Instance.new("Attachment")
			attachment0.Name = joint_name .. "Attachment0"
			attachment0.CFrame = desc.C0  
			attachment0.Parent = part0


			local attachment1 = Instance.new("Attachment")
			attachment1.Name = joint_name .. "Attachment1"
			attachment1.CFrame = desc.C1  
			attachment1.Parent = part1


			socket.Attachment0 = attachment0
			socket.Attachment1 = attachment1
			socket.Parent = desc.Parent  


			print("destroyed")
			desc:Destroy()
		end
	end

end

I would like a ragdoll effect when i die, currently (as seen in the video), the character seems to be floating, and the humanoidrootpart not dropping/falling, with occasional sudden jumps in the air.

You should change the humanoid’s state to Ragdoll as shown below
Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)

And turn off the GettingUp state.
Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)

These cause the humanoid to not interact with collider parts and leave it all up to your physics.

Instead of Enum.HumanoidStateType.Ragdoll

It is better to use
Humanoid:ChangeState(Enum.HumanoidStateType.Physics)

And when Ragdoll runs out of Ragdoll you should use
Humanoid:ChangeState(Enum.HumanoidStateType.Landed).

In my game I use this code:

local RS = game:GetService("RunService")
local RagdolledValue = script.Parent:FindFirstChild("Ragdolled")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid")

local Camera = workspace.CurrentCamera

local function Ragdoll(state)
	
	task.spawn(function()
		if Humanoid.Health >= 1 then
			local ragdollConnection
			ragdollConnection = RS.RenderStepped:Connect(function()
				if RagdolledValue.Value == false then
					Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, true)
					Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, true)
					delay(.20,function()
						Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
					end)
					Humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, true)
					Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
					Camera.CameraSubject = Humanoid
					ragdollConnection:Disconnect()
				else
					if Humanoid.Health >= 1 then
						Camera.CameraSubject = Character.Head
						Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)
						Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
						Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
						Humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, false)
						Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
						for i,v in pairs(Humanoid:GetPlayingAnimationTracks()) do
							if v.Name ~= "Animation1" and v.Name ~= "Animation2" then
								v:Stop()
							end
						end
					end
				end
			end)
		end
	end)
	
end

RagdolledValue:GetPropertyChangedSignal("Value"):Connect(function()
	if RagdolledValue.Value == true then
		Ragdoll(true)
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.