Armor via health

I need armor working via the health, so far, if humanoid health is above 100 then it is showing it, that part working great. However, when humanoid health drops under the 100 it’s showing you negative health. Which can be seen below on screenshot. Is there anyway how I could put a cap, so it doesnt go below 0 and over than 50 (150)?
image

local player = script.Parent.Parent.Parent.Parent.Parent

player.Character.Humanoid.HealthChanged:Connect(function()
	local hel = player.Character.Humanoid.Health - 100
	if hel <= 25 then
		script.Parent.Text = math.floor(hel)
	else
		script.Parent.Text = math.floor(hel)
	end
	wait()
end)

You just want to limit the number between 0 and 50?
You can use min and max. The return the smallest number and the largest number, respectively.

local larger = math.max(health-100, 0) -- health-100 or 0, whichever is greater
local smaller = math.min(larger, 50) -- 50 or the last number, whichever is smaller
script.Parent.Text = math.floor(smaller)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.