Good to know, thanks for the info.
Oh, hm didn’t think about that. Also by any chance would you know if theres a way I could use the randomnum to calculate the chances to getting a certain pet; There would be a 25% chance of getting a common pet
No no, its all good, ANYTHING would help, I spent the longest time thinking about this and I can’t get it so Thank You
I just uploaded a copy of my MathUtils module that I used on a project. In it you’ll find instructions on how to use the WeightedLottery function. Take a look:
Of course, i’ll try it out, my studio is lagging at the moment but I’ll make sure to tell you if it works Thank you so much!
So I have read through the the module but I’m not quite sure how to use it, could you help me out on this. Thank you
Are you trying to think of ways to get a random pet based on their rarities or get the percentage for the chances of each choice?
I’m trying to get the percentage for the chances of each pet so that I can display it on a gui whenever a player comes near one of the eggs.
In that case you could just use the rarities themselves because (75 + 24 + 1) is 100 so 75 is 75% of 100 and etc. Or maybe you’re looking for something different?
I noticed the same but my problem is that those are the chances for the rarity meaning that there is a 75% chance to get a common, but common has a table of pets and I need the script to calculate how much of a chance there is to get a dog for example. rather than getting a common pet if that makes sense. Sorry I’m not the best at explaining
Later you do the rarity chance you should specify the table of pets and then you get the length of the table
(If its a table then it would be math.random(1, #table))
(If its a folder or something that has childrens then its math.random(1, #theThing:GetChildren()) )
So basically you would do something like this
local theChosenPet = math.random(1, #table)
In you’re code I don’t see anything that gives certain pets in a tier a chance to be chosen, if I am mistaken can you point it out to me?
This function chooses a random one everytime activated
The code you have there does not necessarily get random pets based on weight(chance), so the percentage of certain pets to be obtained cannot be calculated. Again if I am wrong please point out the line(s) of code that achieve that.
So the code, when fired gets a “randomnum” from 1,100 and if the “number” is lower than or equal to the random number it chooses a random pet from the table( it goes through the rarity table and checks if thare are any pets in that rarity. If there is it chooses a random one), you could do something like
local pet = petModule.choosepet()
print(pet.Name.." chosen")
and the output would be something like “Doggo chosen”
again sorry not the best at explaining
Again I do not see how you are getting a random pet from a tier based on chance, all I see is it getting a random number from the choices of pets in that tier and returning the value of the index of that tier. In my knowledge I don’t think there is a way to get percentages of the chances for it to return each choice given to math.random().
We could surely help you set up a way to put chance on certain pets in a tier.
Sorry for a late reply, but here’s what Ive done, the function chooses a pet based on its rarity weight. I’ve just made it more clear making an inventory gui. when you click the button to buy an egg, the function chooses a random pet and just for visuals right now i made it go into the inventory. here’s a video of that
I tried calculating the chances by doing the chance of getting a common for example divided by the number of pets inside of the rarity. 75% of a common/3 common pets results in 25% of getting a common pet? But I don’t know how to use that information in the script
Sorry for my late reply, if you already figured out your way to calculate the percentages then make a function in your module that returns the calculations.
sorry, I tried making one but I couldn’t. I made a function with a for loop that goes through the number of pets there are in total and calculates the chances of every single pet that didn’t work because it kept cloning the cells into the gui i want the percentages go into (also the percentage was the same in each one so that didn’t work) Thank you for helping though. Really appreciate it, and also my bad for the late reply