Reviving a player at 0 hp

How to revive a player when the player is already at 0 hp? I cannot make it work correct as the player’s joints anyways break.

Found a solution:

local player = game.Players.LocalPlayer

player.CharacterAdded:connect(function(char)
    char:WaitForChild("Humanoid"):SetStateEnabled(Enum.HumanoidStateType.Dead, false)
end)
6 Likes

I suggest using the search function as this question already seems to have been answered before:

Either way, as the solution says you are probably best of making the player die after reaching a health value of 0.1 or below and making sure your weapons won’t kill the player if they are already at this value.

4 Likes

I think there’s a property in humanoid called BreakJointsOnDeath btw. Not sure if that’d let you revive the player but it’s just to keep your joints in place.

1 Like

When a Humanoid reaches 0 health, it enters the Death state which cannot be exited. You can prevent the death state by hacking it off but relying on hacks is a bad plan. So you have three options: custom health tracking, clamping the health above a certain threshold and determining anything near the health floor (e.g. <1 health) as a death state or propping up an artificial character model after the death of the original. I recommend the former two, especially the second, over the latter.

1 Like
game.Workspace.ChildAdded:connect(function(Character)
    if Character.Name = game.Players:FindFirstChild(Character.Name) then
        if Character:FindFirstChild("Humanoid").Health == 0 then
            Character:LoadCharacter()
        end  
    end
end)

I didnt understand too much what you said,but this may be the solution(I’am not too sure if it will work)

You cant revive a player on a localscript. You must use serverside script.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        local Humanoid = Character:WaitForChild("Humanoid")

        Humanoid.Died:Connect(function()
            Character:LoadCharacter()
        end)
    end)
end)

I’m no scripting master but isn’t there a way to keep all of the player’s joints welded together even after they die? Also I’m sure there’s a way to decrease the player’s HP to 0 and not kill them. Also make sure the script is not inside a LocalScript but just a regular Script.

Yes, you can preserve joints on death. You can keep Humanoids alive at 0 health as well but hacking the death state off is not recommended, you should always keep a minimum threshold such as 0.01 health that’s maintained by setting the health to the result of math.max between 0.01 and the new health (>0.01 will return the new health, <0.01 will return 0.01).

2 Likes

As genious said,there is an propertie at an humanoid,“BreakJointsOnDeath”,but i dont know how to change it from studio,but from script it may be possible.

game.Workspace.ChildAdded:connect(function(ChildAdded)
    if ChildAdded.Name == game.Players:GetPlayerFromCharacter(ChildAdded.Name) then
        local ChildAdded = PlayerCharacter
        while true do 
            PlayerCharacter.Humanoid.BreakJointsOnDeath = false
            wait()
        end
    end
end)

I added an while loop,because PROBABLY,the propertie disables every death the player has(I’am not very sure if this code will work)

Oh,sorry,i had readed wrong…

(cringe moment.)

Setting a Humanoid’s health to 0 will kill it. That’s not what I said. What I said was to clamp the Humanoid’s health, which can be done by choosing the maximum value between a small threshold and the current health. If it is above the threshold it will set the health to that number, but below it will choose that number.

Humanoid.HealthChanged:Connect(function (newHealth)
    Humanoid.Health = math.max(newHealth, 0.01)
end)
6 Likes

Another option is to save the players location before death, save their tools and just about everything, and then call Player:LoadCharacter(), destroy the force field, and put everything you saved from their last body back into the character and CFrame it to the saved location.

1 Like

Its pretty buggy, ive tried it before and i can confirm that its pretty lazy and buggy to use this method, the best you can do is try to clamp the humanoid’s health as colbert explained

1 Like

Great suggestion! But I have a question, how would you create a minimum threshold for the Humanoid Health?

The explanation is in both the posts I made on this thread, with a more explicit code sample showing that in the second post. Use HealthChanged to figure out when the Humanoid’s health changes and use a function from the math library to keep their health above a certain value.

Maybe this topic can help you

I’m not the one looking for help though. Additionally, worth quickly saying, but Humanoids can’t come back from the Dead state. That’s why I mentioned in all my posts above that Humanoids need to have their health clamped to a small value and you need to simulate death/knockouts yourself.

Oh, I meant to reply to the topic, not you, sorry. Yes I think this is true, that Humanoid must be kept above 0hp,im pretty sure this topic says something about that

You can somehow survive Humanoid.Health = 0 by using Humanoid.HealthChanged and checking if health is 0 then change it to a positive nonzero number.
I only tested it in Studio, so im not sure if it works in the actual game

Edit: I tested it in-game and it still works, but this is only for Humanoid.Health = 0 and not Humanoid:TakeDamage() or Humanoid = Humanoid - number

Make a module that has a damage function.

In that function you give damage to the given humanoid.

Heres an example function, this does not completely do everything. It does have some bugs because I just wrote it based on what my brain says. You should be able to see what im trying to say by reading the script. :smiley:

function module.GiveDamage(damage, targetHum)
     local knockedDownAnimation = script.Animation -- Change this to where ur animation is
    if (targetHum.Health - damage > 0.1) then
          -- If the damage does not reach the 0.1 mark then you wanna give the damage
         targetHum:TakeDamage(damage)
    else 
         targetHum.Health = 0.1
         local load = targetHum:LoadAnimation(knockedDownAnimation) 
         -- Make sure to have an animation when a player is knocked so that you have a animation base
         load:Play()
         targetHum.Parent.HumanoidRootPart.Anchored = true
         spawn(function()
              load.Stopped:Wait()
              targetHum.Parent.HumanoidRootPart.Anchored = false
         end)
         repeat wait() until targetHum.Health > 50
         load:Stop()
    end
end)

And what if players want to reset using the reset button?

1 Like