BreakJointsOnDeath does not kill player?

I disabled the BreakJointsOnDeath on my players humanoid, but when my player has 0 health, humanoid state is RunningNoPhysics. I try to force it to be Died state, still doesn’t work. I have a custom character loading script and since I made the Death animation script, the player does not respawn, because humanoid.Died() does not get called. How do I fix this problem?

3 Likes

You can just detect when the health is changed and if it is <= 0 then do the code for .Died

2 Likes

if you made your custom death script, check if health ==0 then
player:LoadCharacter() – it respawns character

2 Likes

Use Humanoid:ChangeState in a local script. Change the state to Humanoid.Dead (The Humanoid died. Changing a Humanoid’s state to this one will kill it.)

More information about using HumanoidStateType can be found here: HumanoidStateType | Documentation - Roblox Creator Hub

I hope I helped :slight_smile:

1 Like

Already tried it, it didn’t even let me change it to Died state. Maybe because the death animation is playing?

2 Likes

How about the script checks if the health is below or equals zero and if it is true the custom death animation is playing and the character respawns. You can load the animation using script and use Player:LoadCharacter to respawn the player. You can add wait() until the respawn.

1 Like

I believe it is Humanoid:LoadAnimation to load the custom death animation.

1 Like

I already have custom character loading and humanoid state handling scripts, the thing is that I could save some time if I could somehow make humanoid state to Died and I wouldn’t need to change those other scripts. Also, quite interesting, when I use the same death animation script for a custom character, it works perfectly well. The custom player character dies and respawns with no problems.

1 Like

Well, if you used this method:

:SetStateEnabled()

then the problem is that if you put the 2nd parameter to false while the 1st parameter being the Dead state then it wont let your player die.

I use SetStateEnabled to enable Died state, then used ChangeState to force Died state, but nothing happens and state is still RunningNoPhysics. I did some more tests, looks like even more code broke without even touching it. Could this be the new Roblox Studio update issue?

Here is death animation code:

function onHealthChanged(health)
print("Health changed: "..health)
-- Check if player is dead.
if health <= 0 then
	-- Anchor the character.
	character.HumanoidRootPart.Anchored = true
	
	-- Stop all other animations from playing.
	stopAllAnimations()
	
	-- Play death animation.
	local deathAnimTrack = humanoid:LoadAnimation(deathAnimation)
	deathAnimTrack:Play()
	deathAnimTrack:AdjustSpeed(DEATH_ANIM_SPEED)
	
	-- When Keyframe "Pause" is reached, freeze the animation.
	deathAnimTrack.KeyframeReached:Connect(function(keyFrameName) 
		if keyFrameName == "Pause" then
			-- Pause the animation.
			deathAnimTrack:AdjustSpeed(0)
		end
	end)
end
end

This code worked before with custom character, now it doesn’t work after I restarted Roblox Studio.

Edit: by doesn’t work I mean humanoid state is not set to Died. It used to before.

1 Like

I found where the problem lies. When I anchor HumanoidRootPart, the player can’t be in Dead state for some reason. Still don’t understand why this script worked well before and now doesn’t.

Listen for died event:

Humanoid.Died:Connect(function() end)

Kill the humanoid:

Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, true)
1 Like

I already was listening to died event:

Humanoid.Died:Connect(function() end)

but the problem was that this event was not fired when my humanoid had 0 health. I enabled Dead state, then I forced that state by using humanoid:ChangeState() and still the Died event does not get called.

Try using SetStateEnabled instead.

1 Like

I already said that I enabled Dead state with SetStateEnabled.

If that doesn’t work, I’m pretty sure Character:BreakJoints() will. If not, you’ll have to do some research.

1 Like

I finally found my problem. Can’t anchor the HumanoidRootPart through a LocalScript. I fixed the problem by making a separate death server script and a death animation local script.