Hello! I was wondering, how could I make chance based events? (don’t get me wrong, I’m not asking for full scripts).
An example would be that you have a lamp in like a simulator/tycoon type game. There is a certain chance that the lamp will break or that the electricity will cut out, meaning that the lamp will stop shining. If you purchase a backup electricity generator, the chance will decrease.
I was thinking about certain ways, such as math.random(percentageChance, 100), which then would return either true or false values (break the lamp/not break the lamp), but I’m not really sure about that.
local accuracy = 10 -- i like to add this to control how many decimals the percentage has
local randomNumber = math.random(0,100 * accuracy)
local chance = 33.3
if randomNumber < chance * accuracy then
print("you are lucky")
end