Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a way to make it so that Humanoids don't die at 0 health?

Is there a function to do this? or something?

7 comments

0

It may be possible if you create a second humanoid, but once your health hits 0, roblox will kill the character. You could try adding checks when taking health off to limit health to just 1 instead of 0, or add a forcefeild if their health hits 1.

0

I can't find any way to do this. Is there any specific reason to why you need to do this?

0

^ Pretty much. But a way you can do it is to just double or whatever the player's health, so that it takes a while for them to die.

0

Basically why i want to do this is so that if a player gets down to 0 health they don't actually die.. they just go down and they can be revived.

0

u guys blind or something

0

not in an insulting way

0

@TheLuaBanana what do you mean?

3 answers

✓ Accepted answer

Humanoid:SetStateEnabled()

Set the "Dead" state to false like this:

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

This will disable the character dying once the health reaches 0. I think I made a revive script before and using Character:BreakJoints() kills them no matter what, can't confirm since it's been a while.

Players.CharacterAutoLoads

You must disable this or it'll respawn the character once their health reaches 0. You have to create your own respawn system and what not.

2 comments

0

It kind of did work, but I can't seem to get the controls back after my character health hit 0, and I brought the health back up. Any idea?

0

I figured it out! SetStateEnabled doesn't replicate to client! So in order for this to work you must do it on the client aswell!

Not really, there may be someone who discovered a SUPER hacky way around this but one, its hacky, and two most developers opt for this:

Creating another value that acts as health. e.g a NumberValue located inside the humanoid that acts as Health

but what if i want to do something when they loose all health?

changed event

local health=humanoid.HV

health.Changed:Connect(function()
	if health.Value<=0 then
		--'died'
	end
end)

How about takedamage?

local health=humanoid.HV

function TakeDamage(val)
	--to keep it between 0 and 100
	health.Value=math.clamp(health.Value-val,0,100)
end

You could even set this to a BinableEvent

local health=humanoid.HV

script.TakeDamage.Event:Connect(function(val)
	--to keep it between 0 and 100
	health.Value=math.clamp(health.Value-val,0,100)
end)

HV being the NumberValue

This answer is based on what you mentioned in your comment.

A simple way I can think of doing the Health is to make a NumberValue and change the player's health based on what this number is. If the number is less than 1 then don't change the player's health. Here's a bit of example code.

local function ChangeHP(Player, Amount)
	if game.Players:GetPlayerFromCharacter(Player) then
		local Humanoid = Player:FindFirstChild("Humanoid")
		if Humanoid then
			local FakeHealth = Humanoid:FindFirstChild("FakeHealth")
			if FakeHealth then
				FakeHealth.Value = FakeHealth.Value + Amount
				if FakeHealth.Value < 1 then
					print("Player is downed")
					Humanoid.Health = 1
					FakeHealth.Value = 0
				else
					Humanoid.Health = FakeHealth.Value
				end
			end
		end
	end
end

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		if Humanoid then
		local FakeHealth = Instance.new("NumberValue")
		FakeHealth.Name = "FakeHealth"
		FakeHealth.Parent = Humanoid
		FakeHealth.Value = Humanoid.Health
		end
		
		while wait(1) do
			ChangeHP(Character, -10)
		end
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.