I think you are over complicating your thinking. First things first... I would do a bit of research on exactly how hit chance is done in an RPG game. There's probably some documentation somewhere, here, or there.
Then I would base your script on that.
-- set as definition script
local hero = game:getLink(VGameCurrentCharacter) -- get current character
local hSpd = hero:getObject(".CharacterValues[speed]") -- get value speed of current character
local hLvl = hero:getObject(".CharacterValues[level]") -- get value level of current character
local hHit = hero:getObject(".CharacterValues[hit]") -- get value hit of current character
local t = {}
t["_temporary_"] = ""
function hit_chance(e)
t["enemy"] = getObject("Characters[" .. e .. "]") -- store linked enemy
t["spd"] = t["enemy"]:getObject(".CharacterConditions[speed]"):getInt(VValueInt)
t["lvl"] = t["enemy"]:getObject(".CharacterValues[level]"):getInt(VValueInt)
t["evasion"] = t["enemy"]:getObject(".CharacterValues[evasion]"):getInt(VValueInt)
-- * --
t["hTotal"] = hLvl + hSpd + math.random(hHit, 100) -- level + speed + random hit value (current character)
t["eTotal"] = t["lvl"] + t["spd"] + math.random(t["evasion"], 100) -- level + speed + random evasion value (linked enemy)
-- * --
if t["hTotal"] >= t["eTotal"] then return true else return false end
end
to use...
-- execute a script
hit_chance("add enemy name here") -- case sensitive
This is just a quick example of return true or false for hit or miss based on difference between current character & the linked enemies speed, level & hit/evasion values. It returns true or false... if it returns true then you would sort out the damage dealt part of the script.
Quick explanation of my math formula (I hate math)...
Say my main character level is currently 22 & my character speed is 13 & my hit % is 75 then what we get is: 22 + 13 + random number between 75 & 100. Then same again for enemy but instead of checking enemy hit % we check their evasion % & if our total is greater than theirs then we return true (hit).
math.random(val, 100) seems a little counterproductive, but you had the right idea in mind as the higher the hit/evasion value to 100 the more chance that you will return a higher value than a lower value. Say the enemy evasion value is 15, which means that the random value could be anything from 15 to 100, which means they have more chance of returning a lower number than a character with a hit value of say 75.