How do I make percent chances?

How would I go about making percent chances and then applying it to things?

Example: there is a 30% chance that this light will turn blue, and a 50% chance that it will turn red.

-- Example, not meant to copy/paste
function PercentRoll(min)
return math.random(1, 100) <= min
end

local roll_for_blue = PercentRoll(30)
local roll_for_orange = PercentRoll(50)

lightColor = roll_for_blue and Color3.new(0, 0, 1)
or roll_for_orange and Color3.new(1, .5, 0)
or Color3.new(0, 0, 0)

Edit: first color3 value was green and not blue rofl

1 Like