Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
IDKBlox 349 Moderation Voter
4 years ago

Is there a function to do this? or something?

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. LucarioZombie 291 — 4y
0
I can't find any way to do this. Is there any specific reason to why you need to do this? aiza_teizuki 15 — 4y
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. Creeperthekid32 70 — 4y
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. IDKBlox 349 — 4y
View all comments (3 more)
0
u guys blind or something TheluaBanana 946 — 4y
0
not in an insulting way TheluaBanana 946 — 4y
0
@TheLuaBanana what do you mean? aiza_teizuki 15 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago

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.

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? IDKBlox 349 — 4y
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! IDKBlox 349 — 4y
Ad
Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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)

Answer this question