errors with my script

Hi!
im working on an energy script for one of my upcoming gamemodes but for some reason this code throws millions of errors at me, i cant seem to find the problem, if anyone else can help that would be superb

Errors:


[ERROR] gamemodes/advw/gamemode/cl_init.lua:118: attempt to index global 'play' (a nil value)
  1. fn - gamemodes/advw/gamemode/cl_init.lua:118
   2. unknown - addons/ulib/lua/ulib/shared/hook.lua:184


My Code:


function setenergy ( ply )
play.energy = 30 -- my global variable
end

local speed = 200

local goal = 30

 function energyregain ( ply )
        if play.energy == 30 then
        ply.MsgN("No Energy Regain Needed")
else
	variable = math.Approach( play.energy, goal, speed * FrameTime() )
	end
end