Revive Player from 0 HP

Hi! My name is DivScripts.

As I wanted to make a revive spell, my script wasn’t working.

I did:

game.Players.PlayerAdded:Connect(function(player)
    	player.CharacterAdded:Connect(function(char)
    		player.Chatted:Connect(function(msg)
    			if msg == "!revive" then
    				char.Humanoid.Health = 50
    			end
    		end)
    	end)
    end)

but this wasn’t working.

Anyone who knows how to make a revive script?

Best Regards,
DivScripts

just save the position of where they died, and then respawn them at that position.

4 Likes

I don’t think you can make the player health go back up after its dead. Try making it so you are downed at 5 health and can not be damaged and maybe then do the spell?

Don’t let anyone damage a player with less than 10 health, then you can disable the controls for the players that have less than 10 health

Examples:

if Health > 10 then
    -- Damage the player
end

if Health < 10 then
    -- Disable the player's controls
end

Simply disable the dead state and use Health.Changed to check when it “dies” instead.

Humanoid:SetStateEnabled(Enum.HumanoidStateType.Died, false)

Make sure it’s disabled upon spawning (CharacterAdded), or, check prior to that the difference between the Humanoid’s current health and the upcoming damage, so you can disable the state prior to that.

This isn’t a good solution, that forces you to be picky about damage.

Alright. So for example:

Humanoid.Health.Changed:Connect(function()
    if Humanoid.Health <= 0 then
        Humanoid:SetStateEnabled(Enum.HumanoidStateType.Died, false)
    end

It’s a easy fix

local WeaponDamage = 12
if Health > 10 and Health < WeaponDamage then
    Health = 9
    -- Damage the player
end

But this is just for learning, I agree that this is not a good way to do it

1 Like

As long as the Humanoid never dies, things like FloorMaterial can be seen and calculated, which helps developers with (for example) things like ground impacts.

So your method works too as you said, it’s all about not making the Humanoid die in the end.

1 Like

The thing is, I do this for a comission. So I don’t have acess to all the other spells wh someone else made. So I can’t use your method.

Oh I see, you can’t see the damaging script? That makes the comparison impossible.

Make the state disable on spawn then.

At first I meant to make the damage and current health compare, and if it was 0 or lower, it would disable the state before taking damage.

So like for example:

CharacterAdded → Humanoid:SetStateEnabled(Enum.HumanoidStateType.Died, false)

Yeah, make sure to define the Humanoid as a local variable and use WaitForChild() to avoid errors.

Alrighty. I will try it out. Thank you. :slight_smile:

1 Like

Now I’m infinite long dead and I don’t respawn. I think I will try to reload the character and TP the char to his old position.

You need to manually script the respawning process.

I recommend player:LoadCharacter()

Id recommend moving the Chatted event out of the CharacterAdded event as this may cause a large memory leak. Every time the character dies, it will add an additional event. These events will gather up, and lets say the character had died 100 times, the next time the character chats, it will set char.Humanoid.Health = 50 100 times instead of once. This can be very dangerous and will cause large amounts of lag every time you run that command.

That is not a possible thing to do. Once a Humanoid has 0 health, it will automatically have its state as “Dead”, which can not be changed. Once the player respawns, the old character is destroyed & Roblox requests a new one, that’s how you respawn.

What I suggest doing: Making a player’s Humanoid have, for example, 120 max health. Whenever the health is only 20 or below, down the player, the they can get revived if someone types “!revive”
Here’s an example script:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local humanoid = char:WaitForChild("Humanoid")
		humanoid:SetAttribute("Downed",false)
		humanoid.HealthChanged:Connect(function()
			if humanoid.Health <= 20 then
				humanoid:SetAttribute("Downed",true)
				--you can put other downed limitations here
				
			else
				if humanoid:GetAttribute("Downed") then
					humanoid:SetAttribute("Downed",false)
				end
			end
		end)
	end)
	player.Chatted:Connect(function(text)
		if text == "!revive" then
			if player.Character and player.Character.Humanoid:GetAttribute("Downed") then
				player.Character.Humanoid.Health = 50
			end
		end
	end)
end)

Also please don’t put player.Chatted when to CharacterAdded events, otherwise that might cause some memory issues. The event does not get disconnected whenever the signal is fired again.

Incorrect, read above.

Disabling state Died prevents the whole thing from happening.

Disabling died or BreakJointsOnDeath also prevents automatic respawn.