How to make a health cap

so im currently developooping a combat game, and although i know some aspects, i am unsure how to make it so the player cannot die, for example I want the health to cap at 10 hp, and then execute a kill animation.

I dont want it to automatically die, anyone have any solutions?

this may be confusing but i want it so when the player is hit, it doesnt go to 1 hp and “oof” I want it to have a limit which will be 10hp

You can just put a number value in the player, name it Health, and create a script with the function:

game.Players.Player.Health.GetPropertyChangedSignal(“Value”):Connect(function()
local Value = game.Players.Player.Health.Value
if Value <= 10 then
Value = 10
if game.Players.**Player.**Character then
if game.Players.Player.Character:FindFirstChild(“Humanoid”) then
local Humanoid = game.Players.Player.Character:FindFirstChild(“Humanoid”)
Humanoid.Health = Value
– Player Animation Code…
end
end
end
end)
If you want to, you can put a variable for the player.

3 Likes

You can use math.max to limit the HP drop to 10 HP. For example, when your punches/sword deals damage, make it go like Humanoid.Health = math.max(10, Humanoid.Health-Damage)

1 Like