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.
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.
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?
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).