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 3 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.

500 Coins - 95% = Common
1000 Coins - 85% = Common
2500 Coins - 75% = Rare
6000 Coins - 25% = Epic
10000 Coins - 10% = Legendary
0
100% is full, your math doesn't make any sense. Just do it to 100%, to 1. Ferrarimami 120 — 3y

3 answers

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

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

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

and then

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

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

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

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

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

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

example:

local ChanceTable = {
    ["Common"] = 95, --Commas are used to separate a value from another
    ["Uncommon"] = 85,
    ["Rare"] = 75,
    ["Epic"] = 25,
    ["Legendary"] = 10,
}

local RewardTable = {
    ["Common"] = 500,
    ["Uncommon"] = 1000,
    ["Rare"] = 2500,
    ["Epic"] = 6000,
    ["Legendary"] = 10000,
}

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:

local 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.

local CurrentRarity = "None" --Have the variable in advance

for RarityName, RarityPercent in pairs(ChanceTable) do
    if RNG < RarityPercent then
        CurrentRarity = RarityName
    end
end

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:

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

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
3 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