How To Detect When A Humanoid's Max Health Changes

How would I detect when a humanoid’s max health changes?
In the Output it says "Attempt to index number with ‘Changed’.

local maxhealth = humanoid.MaxHealth
maxhealth.Changed:Connect(function()
	print("1")
end)
1 Like

This is not how you detect if a value changes in an instance.

Try learning what Instance:GetPropertyChangedSignal() is. It may help.

You should not use Humanoid.MaxHealth but should use only Humanoid then use
humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(function()
--Your code
end)

1 Like

The reason why the above answer is how you should do it:
humanoid.MaxHealth gives you number. It can be 100, it can be 250 etc.
humanoid.MaxHealth.Changed is exactly the same as 250.Changed, which does not exist.
humanoid:GetPropertyChangedSignal("MaxHealth") will give you a Signal object, which is what you can :Connect() to.

A number does not change, just like how you can’t say that 100 now means 150. But the amount of something can change.
Try it:

local maxhealth = humanoid.MaxHealth
print("Max health: " .. maxhealth)

humanoid.MaxHealth = 300
print("Max health was changed to: " .. maxhealth) -- maxhealth is a number, numbers do not change.
print("But actually, it was changed to: " .. humanoid.MaxHealth) -- MaxHealth is a property of humanoid, it can change to any number at any time. This gets the newest number that was put in this property
1 Like