Shouldnt a MaxHealth Change automatically reduce Health to new MaxHealth

title describes it mainly.
server script changes a humanoids max health to 80
the humanoid health however remains at 100 until set otherwise

i have no problem with just adding this on manually just curious if this is a bug or something open for discussion.

1 Like

Seems to be a bug, changing the Health property after setting MaxHealth to something lower automatically clamps it and sets it to the new MaxHealth.

Basically, if you set MaxHealth to 50 and then set Health to 1000 from 100, then it’ll automatically go down to 50, and for some reason act like you took damage and show the red damage effect.

2 Likes

I think this is more of an discussion topic than a bug, the Health Script has remained unchanged for a large amount of time, and doesn’t handle this issue. A temporary solution would be to add this block of code above the health script while loop:

--The Health script can be located under the player character, either fork it, or create a new script for handling this issue
Humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(function()
	local max = Humanoid.MaxHealth
	if Humanoid.Health > max then 
		Humanoid.Health = max 
	end
end)

PS: Personally, I consider the Health script outdated, it must be updated for efficiency and issues like this.

1 Like

unfortunatly i dont have access to disccusion for whatever reason (; and i alreadhy added that just came hhere for other thoughts

This seems a little long-winded, you could just write a wrapper which changes both properties at once or just explicitly assign each property when necessary.

local function changeHealth(humanoid, health)
	humanoid.MaxHealth = health
	humanoid.Health = health
end

This will give the humanoid max health, even if they have less than the max. That’s why I used the if statement.

It depends on what behavior you’re trying to achieve, I was under the impression that the thread’s poster wanted them to be changed in tandem with one another. It’s a relatively simple change.

local function changeHealth(humanoid, health)
	humanoid.MaxHealth = health
	humanoid.Health = if health > humanoid.Health then humanoid.Health else health
end

yeah PAGOTATZIS" is correct here

^ is exactly what happens

if you need context as to why urs doesnt work :
food poisoning reduces the max health, to 80 you can get food poisoning when your health is less than the max so i dont want to increase the health to 80 rather reduce it if its over the max health.

It does work it’s just not the desired behavior, the second code snippet I provided would fit the criteria for the desired behavior.