Random RPG Battle System in Lua
Since you are making calls to math.random a lot, keep a local copy in your code:

local random = math.random




Why are you switching between io.write and print statements? Use a string.format to format the data as you want:

print( ("You dealt %d damage!"):format(attackdamage) )


The above is merely a representation. It can be made a lot better (by putting templates as variables etc.)



n = math.random(10) + 1


The above will generate n in the range of 2 to 11. From the docs:


  When called with two integers m and n, math.random returns a
  pseudo-random integer with uniform distribution in the range [m,n].
  [...] The call math.random(n) is equivalent to math.random(1,n).


And, no need for keeping a temporary variable (here n):

enemyhp = 10 * random(10) -- better yet, use random(10, 100)




escapechance = math.random(2)
if escapechance == 1 then
escape = true
end


can simply become:

escape = random(2) == 1




Convert your input to lowercase first. Players might enter Attack or ATTACK too.

if input:lower() == "attack"


or

local input = io.read():lower()




Most important

You should encapsulate your player, enemies etc. inside objects. Lua supports a rough implementation of OOP design using tables. Read the Lua PiL chapter #16