Why won't my infinite health script work?

I’m trying to make the player have infinite health but my script won’t work. It is a local script in StarterPlayerScripts.

local player = game:GetService("Players").LocalPlayer
local char = player.Character

char:WaitForChild("Humanoid").Health = math.huge

First:
Not sure but math.huge() might not be assignable as a number, try setting it to something like: 99999999999999
Second:
It gets updated once, try putting that in a while loop

This wont work on the client, You must place it in a Server-Sided Script

Also another issue is that you’re setting the player’s health instead of the player’s MaxHealth, Script wise you’d want to do something like this.

local player = --Get the player you want here
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

humanoid.MaxHealth = math.huge
humanoid.Health = math.huge

The reason this happens is due to the player’s MaxHealth clamping the player’s health to what its set (100 by default), you want to set the MaxHealth to the float limit aswell as the Health

1 Like

This is not practical. Nor, would this be reliable. If math.huge wasnt an assignable number, why would it exist?

As @VanillaMokah said, you must set the MaxHealth first, then the Health.

Besides, you cant change health on client. You must do it on Server.

--Server script
local parent = script.Parent
local human = parent:WaitForChild("Humanoid")

human.MaxHealth = math.huge
human.Health = math.huge
1 Like

Sorry, I meant assignable to Health, as for some things you can’t assign math.huge() (at least, from my experience)

Instead of giving them infinite health, a better design choice would be to simply not damage them in the first place. For example, you could make a sword not damage the player if you don’t want them to die.

@Dede_4242 math.huge is not a function

math.huge is a “number”, the same with math.pi, and these numbers are useful for math.

Its basically the Same idea behind:

Vector3.zero Vector3.one Vector3.xAxis Vector3.yAxis Vector3.zAxis
CFrame.identity

Well, when I try doing

local randomNum = math.random(math.huge(),math.huge())

That doesn’t work, and I meant it might not be assignable as a number to health, as it (seems) to be for math.random()

math.huge does not require parenthesis to function, as it is just number, and not a function.

Plus, math.random cannot handle numbers above the 32 bit Integer Limit, which is around 2 billion, math.huge is way above that.

local int32 = (2^31) - 1 -- The 32 Bit Integer limit

print(math.random(-int32, int32)) -- max field for math.random

Okay, now I understand why it errored, I thought it wasn’t assignable to math.random() by default…
Thanks(I also tried without parenthesis’s)

this isn’t very reliable but work,
each time the player loose health, reset the health to the maximum humanoid health

if you want it very reliable you should do check, like if an player shoot another player, check if the shooted player isn’t invincible, make him take the damage

script:

local Humanoid = Character.Humanoid --replace the name

Humanoid.MaxHealth = 100000000
Humanoid.Health = Humanoid.MaxHealth


Humanoid.Health.Changed:Connect(function()
    Humanoid.Health = Humanoid.MaxHealth
end)
1 Like

Instead of Humanoid.Changed you should use Humanoid:GetAttributeChangedSignal(“Health”)

Humanoid.MaxHealth = 1e8 -- equivilent to "100000000"

Humanoid.Health is a number, not a Instance, it anything its Humanoid.HealthChanged

Arent all of these irrelevant to the actual question of the OP? You guys should maybe stop giving answers as this question already has an answer.

Sorry but may I ask why we aren’t allowed to help the OP even more? What we are telling him is a way of setting the Health to its maximum when it’s damaged