I'm trying to script one of my first gears and I want the base damage to be a random number between 5 and 10. Can someone help me or post a wiki link or YT tutorial? I know it's a "noob question" but I actually don't know how to do it.
local LocalDamage = 5 -- Instead of 5 damage I need the damage to be a random number between 5 and 10
Use the math.random()
function.
math.random() -- initialise math.random local damage = math.random(5, 10)
"The thing that many developers don't know is that math.random() does NOT generate complete pseudo-random numbers at the first time! Lemme explain. On some operative systems, like OS, the first pseudo-random generated number (the first math.random()) is not completely random. So, when we use math.random() for the first time in our game, it could not work properly on some devices and it could generate a 'not random' number at all." - Aimarekin
"But, as to ensure the number will be complete random, we must use a math.random() for no purpose before it." - Aimarekin