Gmod DarkRP No Health Above 100!!!

Ok basically I got this food mod with food but you can eat it and your health can go past 100 so I need someone to make me a small bit of code that makes it so if you have 100 health your health can no go above that

1 minute code right here, not sure about GetHealth():

function HealthBelow100()

for k,v in pairs( player.GetAll() ) do
if ply:Health() > 100 then
ply:SetHealth( 100 )


hook.Add( “Think”, “HpBelow100”, HealthBelow100 )

Try that.

EDIT: Thanks, Willox

SetHealth is right, GetHealth should just be Health

Rather than using a Think hook in Humble’s example, if you can find the code where the health is added when you eat the food just add a simple check to make sure it doesn’t go over 100.

@Willox Your code does not work

If you want it to be automated for you, when you eat; make a helper function.

Clamp the value:

Player:SetHealth( math.Clamp( Player:Health( ) + foodHealthValue, 0, 100 ) );

@Acecool I added that to the code and it didn’t work :frowning:

Food Mod on github has the limits you want.


This has been solved by OasisRP

Then maybe setting the thread to ‘solved’ would be a good idea?