i know there's a solution already, AND that there's a 3 year gap between comments, but i'm a starting lua programmer that was looking for challenges, and here i am. i made a function dice code of 13 lines without adding up the numbers, but configurable sides and rolls.
function Dice(rolls, sides)
if rolls >= 1 and sides >= 2 then
local amount = 0
local rolls2 = 0
rolls2 = rolls2 + rolls
repeat
rolls2 = rolls2 - 1
dice2 = math.random(1, sides)
amount = amount + dice2
until rolls2 == 0
return amount
end
end
print(Dice(2, 6))
print(Dice(4, 6))
print(Dice(6, 6))
print(Dice(8, 6))
print(Dice(10, 6))
P.S:
use dofile("") and print(Dice(x, x))
2nd P.S:
i found out it automatically adds up.