How to revive a humanoid after death?

You can write your topic however you want, but you need to answer these questions:
1.I Want to revive a Humanoid after death.

  1. In the script below I have a script, It revive the humanoid only one time, But at the second time, The Function ChangeState does not work.

I Want to revive a None playable character “NPC” not a player.

If there is any other solution I have no problem with it, I Just want it to work.

Humanoid.Died:Connect(function()
	if Character["Main Pet."].Value == false then
		print(Character.Name)
		print(Humanoid:GetState())
	end
	if Humanoid.Health == 0 and Character["Main Pet."].Value == false then
		print(script.Name)
		Character["Respawn time."].Value = 20
		Character.Head["Respawn time."].Enabled = true
		repeat
			wait(1)
			Character["Respawn time."].Value -= 1
			Character.Head["Respawn time."].TextLabel.Text = Character["Respawn time."].Value
		until Character["Respawn time."].Value <= 0
		print("Passed the loop.")
		Character.Head["Respawn time."].Enabled = false
		Humanoid.Health = 100
		Humanoid.HealthChanged:Wait()
		print("Should give health.")
	end
end)
2 Likes

This post may be helpful for respawning an NPC :slight_smile:

2 Likes

I Am thankful for the help, But, I Want to revive not Respawn.

1 Like

You can try disabling breakJointsOnDeath and after it died put the health back to 100, i think this can work but is a bit buggy

1 Like

What do you mean by revive?
Do you want the NPC to fall down and then a player has to get and revive him, so like in Fortnite?
If yes, just make it so the NPC never reaches 0 health, put a value inside of the humanoid and whenever someone is shooting make it so it checks for the value and if there is that value just make it so it can’t deal the damage it usually does.
For example set the NPC’s MaxHealth and Health on 110 and make it so if the value is detected and the NPC already has only 10 health left it doesnt do damage. If the shot is the one that makes the NPC reach 10 health just make and if statement that says if NPC.Humanoid.Health >= 10 then… and then make the function where for example you make the npc ragdoll, since NPC’s dont respawn it will just lay there. Then make a function that enabled a proximityprompt that creates when the NPC reaches 10 health and make it so when its triggered the NPC goes back to 110 health and the ragdoll stops.

1 Like

For revive you can not just KILL a humanoid. I say that you keep the humans health above 1 or 5 depending on your needs and then and only then you can revive.

2 Likes

Revive means that the humanoid has died, His health is 0 and It is in a dead state, How can I remove him from that state and get his health back to 100?

I Tried doing this to achieve that:

		Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
		Humanoid.Health = 100
		Humanoid.HealthChanged:Wait()

And It worked, But the second time the humanoid died, That did not happen.

1 Like

Maybe, since an NPC doesn’t respawn without scripts you can just set his health to 0, make it ragdoll and then just wait for someone to come and revive it. And you can just make it so if no one revives the NPC in a minute you make it not ragdoll anymore and teleport it to whereever you want it to respawn.

Edit: Also I’m pretty sure it would not look good if the NPC’s part would get unrigged like when a player dies, since reviving it would somehow be unrealistic then.

From the sound of it, the reference to the humanoid is being nullified due to the death state. When a humanoid dies, any reference to it (i.e. Humanoid = NPC.Humanoid) becomes nil. Therefore, your script would work on the first run; however, the next attempt will break due to the original humanoid being nil.

If you want to create a custom revive system, I would recommend disabling the default behavior of Humanoid.Death. To do this you should disable Enum.HumanoidStateType.Dead on the server like so:

local NPC = script.Parent --// Assuming we place the local script inside the NPC model
local Humanoid = NPC:WaitForChild("Humanoid")
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)

After doing that, the Humanoid.Died function will stop working. So, instead what you will want to do is track the humanoid’s health to see when the NPC would normally die. For example:

Humanoid.HealthChanged:Connect(function(currentHealth)
    if currentHealth <= 0 then
        --// NPC should be downed
    end
end)

When working with NPC health and animation states, you should always use server scripts (unless you only want one player to see the updates).

Hope this helped! :slight_smile:

6 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.