errors with my script

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


[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 ) = 30 -- my global variable

local speed = 200

local goal = 30

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

Take a look at my simple currency system ( only missing read / write functions ):

Or zipped:

And, also take a look at my stamina system:

and extended:

If you want the player to have a variable associated with them, assign it to the player object ( the reference in your case would be ply ) instead of as a global. You end up making more work for yourself when you use globals unless it is a storage var and you’re able to access the data efficiently / easily.

Hopefully, by looking at how the Stamina / Currency systems are done, it’ll help you with your energy system. For Stamina, there are a few instances where Stamina gets “reset” and those times it is networked / networked to reset. Otherwise, things are handled in a shared SetupMove hook so that stamina will always be the same on client and server. Even recovering stamina will be linked without needing to network it.

Hopefully these help.

Acecool, that is not helpful in the slightest.

Make sure “play” is declared on the Client because global variables cannot transfer from client to server without networking. The error literally means that “play” is nil and without seeing the entirety of the code, we cant help much.

Youve meant to use, not, you should really consider looking through your code before posting a ohmygod pls pls pls help me fixing my code thread (or at least use problems which dont need their own thread thread) :vee: