i know how to do this
local num = math.Random(1,3)
if num == 3 then
end
but can i have something that does something like this
local chanceToDoThing = 10/100 --10%
and then it only does something 10% of the time
i know how to do this
local num = math.Random(1,3)
if num == 3 then
end
but can i have something that does something like this
local chanceToDoThing = 10/100 --10%
and then it only does something 10% of the time
You can just insert a value into a table 10 times and make one of those values a different value and then you can detect chance:
For example:
local rng = Random.new()
local tab= {'Rare', 'Common', 'Common', 'Common','Common', 'Common', 'Common','Common', 'Common', 'Common'}
local function returnChance()
local chance = rng:NextInteger(1, #tab)
return tab[chance]
end
print(returnChance())
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
How does :NextInterger() work?
It's basically the same thing as math.random, it takes two parameters: first one is the minimum value and second one is the maximum value, if you do :NextInteger(1, 10) it will choose a number randomly from 1-10, that's what I did here, it chooses a number from minimum 1 to the maximum which is the length of the table then you index the number it returns.
Thanks! :)