Axolotleless

Pet rarity system

Feb 3rd, 2025
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.47 KB | None | 0 0
  1. local RarityTable = {
  2.     Common = 45;
  3.    
  4.     Rare = 35;
  5.    
  6.     Epic = 18;
  7.    
  8.     Legendary = 2; -- these rarities are changeable. Change the numbers how ever you want them!
  9. }
  10.  
  11. local weight = 0
  12.  
  13. for _, Chance in pairs(RarityTable) do
  14.     weight += (Chance)
  15. end.
  16.  
  17. local ranNum = math.random(1, weight)
  18.  
  19. weight = 0
  20. for Rarity, Chance in pairs(RarityTable) do
  21.     weight += (Chance)
  22.    
  23.     if weight >= ranNum then
  24.         print("Rarity "..Rarity.." has been discovered!")
  25.         break
  26.     end
  27. end
Advertisement
Add Comment
Please, Sign In to add comment