What do you need to do ?
A for loop ? math.random() ?
Some help on here please.
math.random()
If you wanted it to be, say, a 1 in 5 chance:
1 | if math.random() < = 1 / 5 then |
2 | -- Boom, golden brick! |
3 | end |
I mean, I myself would use Int Values and math.random
1 | if math.random( 1 , 100 ) < = script.Chance.Value then |
Another way of solving this is to have some sort of rarity
variable, where a golden brick has a 1 in rarity
chance of appearing. Making the rarity of the brick bigger means that it is more rare!
1 | local GOLDEN_BRICK_RARITY = 100 -- this means that 1 in 100 bricks spawned will be golden. Setting this to 1 means a golden brick will ALWAYS spawn. |
2 |
3 | function SpawnBrick() |
4 | if math.random( 1 , GOLDEN_BRICK_RARITY) = = 1 then |
5 | -- TODO: Spawn a golden brick |
6 | else |
7 | -- TODO: Spawn a regular brick. |
8 | end |