Player death animation system doesn't work as expected

  1. What do you want to achieve? I was doing a system when player dies it plays a animation depending of what player was holding (W or S key)

  2. What is the issue? It works only when I’m idling, only one animation plays, i get damaged 100% fourth times (fatality kill lol), and it collides with ground and goes up then breaksjoints

  3. What solutions have you tried so far? i looked other posts it didnt help

local script in StarterCharacterScripts (plz help because i can’t continue with my game)

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local localPlayer = Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()

local humanoid = character:WaitForChild("Humanoid")
humanoid.BreakJointsOnDeath = false

local playerFolder = script:WaitForChild("Player")
local deathAnimFolder = playerFolder:WaitForChild("Death")
local runningAnimFolder = playerFolder:WaitForChild("Running")

local animations = {
	Run = runningAnimFolder:WaitForChild("RunAnim"),
	BackDeath = deathAnimFolder:WaitForChild("BackDeath"), -- falling back triggers when holding S or down arrow while walking or running
	FrontDeath = deathAnimFolder:WaitForChild("FrontDeath"), -- falling in front triggers when holding W or up arrow while walking or running
}

local animationTracks = {}

humanoid.HealthChanged:Connect(function(health)
	if health <= 0 then
		
		stopAllAnimations()
		
		local movementDirection = humanoid.MoveDirection
		local deathAnimationName
		local deathDuration
		
		if movementDirection.Z < 0 then
			deathAnimationName = "FrontDeath"
			deathDuration = animations["FrontDeath"].Duration.Value
		else
			deathAnimationName = "BackDeath"
			deathDuration = animations["BackDeath"].Duration.Value
		end
		
		playAnimation(deathAnimationName)
		
		task.delay(deathDuration, function()
			humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
			humanoid:TakeDamage(humanoid.MaxHealth)
		end)
	end
end)

The trick to doing this is to actually never fully kill the player. When another player lands a move that would kill you, what you would do is set the humanoid health to like 0.1 then make that humanoid unable to be damaged. After you will play your animations, when finished you will finally fully kill the humanoid. Its also good if under this system you use a respawn time of 0

1 Like

Yes, unfortunately some workarounds like this are now required. Roblox made it so that you lose network ownership of your avatar when the humanoid dies, because there were some exploits that took advantage of the time between when the humanoid dies and when your avatar actually gets deleted and respawned.

You can do like sonic suggests and not actually kill the humanoid. You can put the humanoid into the Physics state, disable player control, and animate their death before actually destroying the character. You can also do things like convert the player’s character model to an NPC, giving the server control over it, and swap the player’s character to something like an invisible block that just tracks the NPC.