I keep getting this error and I don’t understand why >:(
[ERROR] lua/autorun/test.lua:5: attempt to call method ‘Health’ (a nil value)
unknown - lua/autorun/test.lua:5
local user = player.GetAll()
local function healthregen()
if ( user:Health() < 100 ) then
if ( user:Health() > 100 ) then return end
timer.Create("playerhealthregen", 0, 0, healthregen)
function Regenerate(ply) -- Move hooks have 2 arguments: a player object, and CMoveData.
if (ply.NextRegen > curtime) then return end -- if player has already regenerated then don't regen more health
ply.NextRegen = curtime + regen time -- set player's next regen time in seconds.
if (ply's health is smaller than ply's max health) then
local current health = ply's health
set ply's health to clamp(current health + added health, 0, ply's max health)
create "Move" hook with Regenerate