Percentage Chance System

  1. What do you want to achieve? Keep it simple and clear!
    I need to make a random number with percentage

Example: I want a 95% chance to get something.

I tried -

local chance = math.random(95, 100)

Although I realized it’s only about a 16.67% chance to get something, not 95%.

Could someone help me?

1 Like

Try doing this:

local chance = math.random(1, 100)
if chance <= 95 then
    -- do something
end
1 Like

You can just do the following:

local chance = math.random(0, 100)
local percentage = 95
if chance <= percentage then print("you won!") else print ('you lost!') end
1 Like

Thanks! I don’t know why I didn’t try doing that.