Local variables are also much quicker to access, global variables are stored in a list and when used are looked up by name, local variables are stored in registers and are accessed instantly.
If you are reading a global variable many times in a script a neat trick is to localise it, for example:
local gX = g_Entity[e]['x']
or even
local Entity = g_Entity[e]
local gX = Entity.x
local gZ = Entity.z
Now simply use gX wherever you previously had g_Entity[e]['x']
Another efficiency you can use is to use squared values for checking distances, for example (assuming you have localised x & z for both player and entity):
local DX, DZ = pX-eX, pZ-eZ
if (DX*DX + DZ*DZ) < (200 * 200) then
gives the same result as calling PlayerDistance and comparing with 200 but is far more efficient (Lua precalculates constant expressions like the 200 * 200 so at runtime they are simply a constant value).
Been there, done that, got all the T-Shirts!