Programming Rarity is Harder Than You Think

188,664
0
2024-05-10に共有
My official Roblox Studio course:
bit.ly/ByteBloxCourse

discord: discord.gg/ay5gc9XcAh

wondered how to make a main menu in roblox studio? or how to create a shop which has working GUI? ive made lots of 2024 roblox scripting tutorials about all the different bits of roblox to give you some up-to-date information about all of its properties and events.

my goal is to simply give some insight on how to use the various features and instances roblox studio, and show you some fun stuff you can do with them. thanks for checking out this roblox scripting tutorial :)

コメント (21)
  • @eclair1616
    No. You just don’t implement rarity. You only want to make it as if there is rarity but in reality you will only get common items, and then you make a button to get legendary with robux.
  • @ZaeNonQ
    me when i use "pick random from 1 to 100" in scratch:
  • @hqTheToaster
    Actually, tbh, I agree with you. Rarity is harder than I think. Haven't had to program rarity before. The closest I got was programing a sort of 'fairness' system in randomizing maps. (1 in a row, and 2 in a row.)
  • I recently began my first game and just so happen to need this rn and u happen to upload this only 4 days ago wow how lucky am i to stumble upon this video thank u 🙏
  • Bro you arrived in a great time, I just got to roblox lua scripting and these videos are teaching me better than my courses lol
  • funnily enough, i made a rarity system using this concept in obby creator like 3 years ago without even realizing this is how rarity systems work in roblox coding
  • @alpha4194
    rarity while seeming initially hard isnt that bad when you get around to understanding tables, so i decided id program a simple lua weighted randomizer and send it here for people to reference if they manage to see this comment first we wanna start off with a table, which is essentially a list. However, each list is only really allowed to have one entry within each line, so to make things more optimized we are effectively putting a small list containing the NAME of the item, as well as its rarity. the rarity in question acts more as a 'frequency' meaning the higher the number, the more abundant the object would become. the template is essentially {(brick color),(frequency)} afterwards we are going to run code that makes a new table (list), that inserts each entry of the original table (list) the number of times of its frequency. Meaning the white brick in the situation (view below) would be written down on the list 100 times. We do this for every entry and effectively have a long imaginary list with 230 entries (in the situation im showing off below.) The final part of this is picking a random number from 1 to the number of entries we have, and just taking the object from the spot in the list! ------------------------- local OurExampleList = { {"White Brick",100}; -- common {"Purple Brick",70}; -- Uncommon {"Green Brick",50}; -- rare {"Orange Brick",10}; -- legendary i guess } local ImaginaryList = {} --imaginary list that is used for later to decide which specific brick we want by inserting the (total of) 230 possibilities into for CurrentIndex, CurrentListEntry in OurExampleList do for count =1,CurrentListEntry[2] do --see the [2]? This is important here because we are sorting through the original example list, which has mini lists and we want the rarities from the mini lists. CurrentListEntry is also technically one of these, which can be found from the CurrentIndex (meaning the mini list {"White Brick",100} is found when CurrentIndex is at 1) table.insert(ImaginaryList,CurrentListEntry[1]) -- places the current entry into the imaginary list, this is run as many times as its frequency end end local Result = ImaginaryList[math.random(1,#ImaginaryList)] --This is another index similar to [2], but we are picking a random entry, from 1 (the first entry) to the TOTAL number of entries (which is essentially 230) print(Result) ------------------------- sorry for lack of formatting or if I was to vague on any topics, but this is just some simple sample code that is a nice stepping stone to understanding absolute essentials to development
  • @azurelava7796
    When you’re using the counter variable while looping through the rarities, this is called prefix sums, and it’s pretty useful for cases like these. But I would say that it’s better to just construct the prefix sums table right after your rarities table is initialized so that you can have faster runtime (especially if there is a lot of rarities).
  • @DpJordi
    I had a system for my now abandoned game. The rarity system was so advanced. It had to take like 8 values in mind when generating. It was basically an armour generator. Where each piece had multiple stats. But certain stats where handled differently. Before i started it, i thought it was gonna be super easy. shit was harder than anything ive done. It also had to work with data saving. I had like 5d array for each stat. Crazy. It used like 5 scripts in total. the rarity script was like 300+ lines. And when i code, i code to make it as efficient as possible. Then i realised, its roblox. It doesnt need to be this complicated. So now i stick to simpler games.
  • @Pygim
    I tried to make a rarity in a different project in a different language, and I gave up, decided to use a simple formula to decide the chance of each rarity. It's not perfect but it gets the job done.
  • i've made a rarity system before and it worked pretty well, i'll try explain it a bit simply here. pretty much have a list of things with a rarity e.g. if its 1 in 1000 make its chance 1000 times all the chances together and this is your weight or totalVal now theres 2 methods i use to expand from this: 1. less complicated but you simply get a random number, sort the list of rarities from rarest to most common, and check if the random number is less than or equal to the (totalVal / chance) 2. allows for multiple rarities of the same chance, because with 1. you can only have something like 1 in 1000 once for example, first you have to create a lowerBound variable and another variable "currentLowest" for example which starts at 0 , for each rarity you set its lowerBound var to currentLowest + 1, and then you create another variable "higherBound" for the rarity, which is set to (currentLowest + totalVal / chance), at last you create the random num and check for each rarity if the number is between the lowerbound or higherbound rarity sorry if this seems all complicated but i kind of just wrote this from the top of my head, hope this helps anyone oh P.S, you'll need to use Random:NextInteger rather than math.random because math.random can't handle large numbers, which can become a problem when multiplying multiple rarites for the total val
  • @Hermit_Wish
    Thank you for this. And to all the viewers here, there's multiple variants of weighted RNG, I would highly recommend to try things out such as making an alternative to math.random(), or find another way to calculate the result. It's a complex system and there's no system that suits all, experiment with it. And with such, another method to this video is to add up all the weight values and multiplying it math.random() with nothing in the parentheses; from there, you go through each weight again and remove it from the accumulated weight that you got from multiplying till you reach 0 or less and return the item that triggered that check. However, by doing this method, you may see that high rarities will appear to be more common depending on the weight you assigned. Again, I highly recommend you to try things out and find new ways; step a little out of your comfort zone, but not by too much, learn from the behaviors and mistakes you come across.
  • @slooshified_
    the way i made a rarity system is more focused on convenience of updating, so instead of making a table or list of rarities i just made a folder containing numberValues and effects of each rarities, so it picks a random number between the lowest and whatever the sum of all values are (all of which are handled by a "ipairs" sequence), which was NOT easy.. but saved me a lot more time adding more and more stuff on it
  • bro you are amazing! I have been trying to understand this for a while.
  • I'm pretty sure that if you were to use ipairs in your for loop iteration, it will go through the table in order. This can help you combat false positives or gaining a rarity lower than you're supposed to roll. for rarity, weight in ipairs (module.rarities) do --do things end
  • I understood none of that but i got the basic. Basically to make rarity you make something and put numbers on it and the Lowest amount of number is the rarest, and you need to put the item in a file and do coding stuff to make the code function, and if the code has an error you watch this video again