How to make a player ragdoll in final position of animation

I am trying to make a player, on death, play a death animation (shown in video) and then ragdoll in the final position. I have tried to move the humanoidRootPart by the displacement of the animation, but I would get a result like shown in the video, is there a way to ensure the player properly moves to the end position and then has no velocity or rotation so I can apply the ragdoll without any jank movement?

local humanoid = script.Parent:WaitForChild("Humanoid")
local Player = script.Parent
local HRP = Player:WaitForChild("HumanoidRootPart")
local RunAnimation = Instance.new('Animation')
local RandDeath = -1
local AnimTime = 0.0
local AnimID = ""
local Offset = Vector3.new(0,0,0) 
local Angle = CFrame.Angles(0,0,0)


humanoid.BreakJointsOnDeath = false

humanoid.Died:Connect(function()
		
	Player._Animate:Destroy()
	
	RandDeath = math.random(2,2)
	
	if RandDeath == 1 then
		AnimID = 'rbxassetid://133609384990226'
		AnimTime = 0.8
		Offset = Vector3.new(0,0,0) 
		Angle = HRP.Orientation
	else if RandDeath == 2 then
			AnimID = 'rbxassetid://127002751186054'
			AnimTime = 1
			Offset = Vector3.new(0,0,5)
			Angle = HRP.Orientation
		else if RandDeath == 3 then
				AnimID = 'rbxassetid://133609384990226'
				AnimTime = 0.8
			end
		end
	end
	
	
	RunAnimation.AnimationId = AnimID
	local RAnimation = humanoid:LoadAnimation(RunAnimation)
	RAnimation:Play(0.00000001, 20, 1)
	task.wait(AnimTime)
	
	HRP.CFrame = HRP.CFrame + Offset 

	for index,joint in pairs(script.Parent:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")
			a1.Parent = joint.Part0
			a2.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2
			a1.CFrame = joint.C0
			a2.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			joint:Destroy()
		end
		
	end
	
end)
1 Like

you can repeat wait for the animation track to finish (AnimationTrack.Ended) and then ragdoll

RAnimation.Ended:Connect(function()
   -- ragdoll code
end)

It plays a lot smoother now which is nice to see, the only issue is for when the player is falling backwards in the mentioned animation, they upright themselves now and fall forward like they just said “Wait, Im not sure I’m dead, oh wait I am”


In theory, the ragdoll falls backwards, but this is a good step forward otherwise, I’ll keep messing with the code to see if I can get it to work at some point

edits made below

humanoid.Died:Connect(function()

	Player._Animate:Destroy()

	RandDeath = math.random(2,2)
	print(RandDeath)

	if RandDeath == 1 then
		AnimID = 'rbxassetid://133609384990226'
		AnimTime = 0.8
		Offset = Vector3.new(0,0,0) 
		Angle = HRP.Orientation
	else if RandDeath == 2 then
			AnimID = 'rbxassetid://127002751186054'
			AnimTime = 1.2
			Offset = Vector3.new(0,0,5)
			Angle = HRP.Orientation
		else if RandDeath == 3 then
				AnimID = 'rbxassetid://135568287596362'
				AnimTime = 0.7
			end
		end
	end


	RunAnimation.AnimationId = AnimID
	game:GetService('RunService').Stepped:Wait()
	local RAnimation = humanoid:LoadAnimation(RunAnimation)
	RAnimation:Play(0.00000001)
	
	RAnimation.Ended:Connect(function()
		HRP.CFrame = HRP.CFrame + Offset 


		for index,joint in pairs(script.Parent:GetDescendants()) do
			if joint:IsA("Motor6D") then
				local socket = Instance.new("BallSocketConstraint")
				local a1 = Instance.new("Attachment")
				local a2 = Instance.new("Attachment")
				a1.Parent = joint.Part0
				a2.Parent = joint.Part1
				socket.Parent = joint.Parent
				socket.Attachment0 = a1
				socket.Attachment1 = a2
				a1.CFrame = joint.C0
				a2.CFrame = joint.C1
				socket.LimitsEnabled = true
				socket.TwistLimitsEnabled = true
				joint:Destroy()
			end

		end

		script:Destroy()
	end)
end)
1 Like

Delete the humanoid and HRP asap after they die

The humanoid wants the player to stay upright.

You might also want to turn on HumanoidState.PlatformStanding before you do that

1 Like

I didn’t find this too useful, but when I delete the Humanoid, the character would just become skin?? not sure why it would do that but it didn’t work to well, I think I’m going to opt for tweening the players position and having the animation be stationary. Its a work around, but if anyone has a solution that works I will mark that as the answer and move on, otherwise I won’t be active on this topic as much

Oh yea I forgot that deleting the humanoid gets rid of the humanoid description :sweat_smile:

Did removing the HRP or setting the humanoid state have any effect? (You would be doing that before ragdolling the character btw)

Also what happens if you don’t apply the offset? Would the character snap back or something?