So I was trying to build a fighting game recently, and I came across an issue.
I wanted to run a function after a humanoid’s health is 0, but before the humanoid state is set to Dead. Does Roblox have any event similar to what I am describing? The humanoid.died event occurs when the humanoid actually dies, not before.
Also, I just found out that doing humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false) doesn’t prevent the humanoid from ceasing action when its health reaches 0, so that might be helpful.
You can disable the death state exactly as you’ve discovered. Simply run humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false) on both the client through a localscript as well as the server through a script.
When the health reaches 0 absolutely nothing will happen. You’ll continue walking around with 0 health as you did with 100 health. Here you can run all the code you want. Then when you’re ready simply re-enable the state and change the humanoid state to the death state.
If you want to take this opportunity to not use the default death mechanics you can make your own with custom animations and utilization of other states like Falling Down, GettingUp, etc.
I would also use a BodyPosition with really high damping inside of the HumanoidRootPart along with a BodyGyro facing forward to keep the dead player in place.
Wait, but when I do humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false), my character cannot move. Don’t get me wrong, it’s better that they not move, but it is an inconsistency to your response.
If you can’t move after setting your state, then either you have code somewhere else running that changes that, or you have not properly disabled the death state on the server and client.
I specifically make use of the disabled death state among disabling some other states to get a knock-out state in my game. Players cannot die in my game. But you can get KO’d and taken hostage.
Edit: It’s also possible that I’m setting the walkspeed. I don’t think I am though. Should be able to walk. In my implementation I have a sprint system so… I set the walk speed to make sure you’re not sprinting in a knock-out state.