Food mod modification

Basically I got a food mod for darkrp, but players can go over 100HP when eating it. I wanted to make a fix and found a bit of code which I added (hopefully correctly) and now I get this error.


04:00:25 Lua Error: [ERROR] addons/majorafood/lua/entities/toffifee/init.lua:43: attempt to index global 'ply' (a nil value) 1. fn - addons/majorafood/lua/entities/toffifee/init.lua:43 2. unknown - addons/ulib/lua/ulib/shared/hook.lua:110

Here is the line in question


function HealthBelow100()

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

end

hook.Add( "Think", "HpBelow100", HealthBelow100 )

What am I doing wrong? Thanks :slight_smile:

[editline]9th February 2016[/editline]

The ENTIRE init.lua in question


AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

function ENT:SpawnFunction( ply, tr )
	
	if !tr.Hit then return end

	local SpawnPos = tr.HitPos + tr.HitNormal * 1

	local ent = ents.Create( "Toffifee" )
	ent:SetPos( SpawnPos )
	ent:Spawn()
	ent:Activate()
	
	return ent
end

function ENT:Initialize()

	self.Entity:SetModel("models/FoodNHouseholdItems/toffifee.mdl")
 
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )

	
	self.Index = self.Entity:EntIndex()
	
	local phys = self.Entity:GetPhysicsObject()
	if phys:IsValid() then
		phys:Wake()
	end
end

function ENT:Use(activator)
	self.Entity:Remove()
	activator:EmitSound("eating_and_drinking/eating_long.wav", 50, 100)

end
function HealthBelow100()

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

end

hook.Add( "Think", "HpBelow100", HealthBelow100 )


If you had taken the time to read the sticky, you would have realized that this is not the place for lua scripting help. Developer Discussion is the section you’re looking for.