Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make an Chance Percentage?

Asked by 4 years ago

So I want to make a chance perchance as you have in pets: Common, rare, epic, legendary and they have their own chance percentage so I wanted to make it with coins so it will pick coins after every 10 min it gives you random coins based on its chance percentage but I found nothing about this topic please help me out.

1500 Coins - 95% = Common
21000 Coins - 85% = Common
32500 Coins - 75% = Rare
46000 Coins - 25% = Epic
510000 Coins - 10% = Legendary
0
100% is full, your math doesn't make any sense. Just do it to 100%, to 1. Ferrarimami 120 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Create a Variable with a random Number between 1 and 100 then check for every:

1if VAR <= 10 then -- Lower/Same = 1-10 = 10%
2--script
3end

and then

1elseif VAR > 10 and VAR <= 25 then --Higher than 10 up to 25 (15%)
2-- script
3end

Then you have 75% left. Let's just make one that will happen with a Chance of 75%:

1elseif VAR > 25 and VAR <= 100 then --Higher than 25, same or smaller than 0 (75%)
2-- script
3end

There are some simpler ways, but this is good to start. Just to copy:

1if VAR <= 10 then -- Lower/Same = 1-10 = 10%
2--script
3end
4elseif VAR > 10 and VAR <= 25 then --Higher than 10 up to 25 (15%)
5-- script
6end
7elseif VAR > 25 and VAR <= 100 then --Higher than 25, same or smaller than 0 (75%)
8-- script
9end
0
If you want help for Currency adding, ask me again Ferrarimami 120 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

First, make two tables containing your values, One for percentages, and another for rewards.

example:

01local ChanceTable = {
02    ["Common"] = 95, --Commas are used to separate a value from another
03    ["Uncommon"] = 85,
04    ["Rare"] = 75,
05    ["Epic"] = 25,
06    ["Legendary"] = 10,
07}
08 
09local RewardTable = {
10    ["Common"] = 500,
11    ["Uncommon"] = 1000,
12    ["Rare"] = 2500,
13    ["Epic"] = 6000,
14    ["Legendary"] = 10000,
15}

This will make it easier to add more rarities in the future.

Now, make a random number generator that goes from 0 to 100 like this:

1local RNG = math.random(0,100) --this automatically gives a number from 0 to 100

Next, make a loop and a rarity variable. This will take your random number and scroll through the rarities, just make sure you have them in descending order (highest to lowest) in the table.

1local CurrentRarity = "None" --Have the variable in advance
2 
3for RarityName, RarityPercent in pairs(ChanceTable) do
4    if RNG < RarityPercent then
5        CurrentRarity = RarityName
6    end
7end

Every time the number is lower than the rarity the "CurrentRarity" variable changes to suit the one you passed.

After this, you can make another loop to reward the player:

1for RarityName, RarityReward in pairs(RewardTable) do
2    if CurrentRarity == RarityName then
3        CurrencyValue.Value += RarityReward --Change "CurrencyValue" to the stat you use
4    end
5end

It is also recommended to use a RemoteEvent if you're doing this on a LocalScript, since it won't save if you're doing this from there

Log in to vote
0
Answered by
FirezDevv 162
4 years ago

Best way to do it is based on the value of a chance, make for loop of that chance and put it in a new table, once all the items are there pick a random item. This will work as a chance system

Answer this question