How can I make a humanoid not be able to take any damage?

I’m trying to make it that a player’s health property cannot be changed. Is there any way to do this, or any alternative way to make a player not take any damage from anything? I tried constantly changing a player’s health to 100 with a while loop, but it isn’t really effective.

1 Like
humanoid.MaxHealth = math.huge
humanoid.Health = math.huge
4 Likes

Wouldn’t that still show the player’s health bar whenever they take any damage?

not really sure, you wouldnt be able to tell any damage was taken though, since their health will be so large

1 Like

There’s really no way you can prevent a humanoid from taking damage; however, you’d have to edit the scripts of items to ignore the player from taking damage

You could also try renaming their humanoid, but some scripts may still be able to find the humanoid and damage it using FindFirstChildOfClass("Humanoid"), but this might also pose the risk of breaking scripts

1 Like

i just thought of another idea. what if you had values of damage in your script, and a value of “block” inside the players character. when you try to damage them in the script, check if the person that was hit had the blocking value to true, if so, damage value = 0. also maybe not very good since values are exploitable i think i heard

It turns out it dosent show the health bar if the player takes damage while the player’s health is inf, thanks!

There’s the ForceField Instance which prevents any damage, but keep in mind the damage has to be caused by Humanoid::TakeDamage.

1 Like

glad i could help!

(30 characters)

hypothetically if I do Humanoid:TakeDamage(0) it would activate the forcefield?

The ForceField will always surround your character, even if you have taken damage or not

The Humanoid would take no damage anyways, ForceField or not.

even if it does he can disable the healthbar with StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)

I mean after I do Humanoid:TakeDamage(0), now that the forcefield is activated, the player won’t take damage. So technically I can just make a while loop that constantly does that and the player will be protected.

The alternative to not making a Humanoid take any damage is to unregister health changes over making them have infinite health. You will have to track their previous health though.

local lastHealth = Humanoid.Health

Humanoid.HealthChanged:Connect(function ()
    Humanoid.Health = lastHealth
end)

This code snippet can be used in any way you want, whether you integrate this with an event-based system where a BindableEvent sets lastHealth and connects HealthChanged, or something.

2 Likes