Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Instead of damage being 5 How could it be converted to a random number between 5 and 10?

Asked by 5 years ago
Edited 5 years ago

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
0
math.random(5, 10) OR math.random() * 5 + 5 theCJarmy7 1293 — 5y
0
Whats with these questions where you can't answer? seith14 206 — 5y
0
You might have posted an answer soon before, at 200 rep all answering/asking question cooldowns are lifted, so you might just need to wait a bit before answering theCJarmy7 1293 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

Ad

Answer this question