Rarity System [Need Help]

Thank you very much for the kind reply, truly helps me out on my programming path!

1 Like

The script he posted means practically nothing? I don’t understand the point of your reply to mine, it’s clear that he lacks understanding of modules or anything related to tables, when he returns “rarityChance” he for some reasons adds {} at the end of it for no apparent reason, “function Rarity = {” doesn’t mean anything and doesn’t work at all, showing lack of understanding of what functions are. I didn’t mean any harm from what I said and was merely giving him resources where to learn the information he’s trying to achieve.

No. If you actually read it, you could see that he is actually trying to help the reader. He is showing how he’d see the system working, calling a function with the table of rarities. Please, for the love of god, stop just being an absolute jerk and actually help these people asking questions. This is a forum… in the category that is SPECIFICALLY MADE for getting help. You should be welcoming, but instead you’re just being useless, making spam replies.


I was not being a jerk in any regard? The function he tried making clearly didn’t work even on the most basic level, one of the most necessary requirements of roblox scripting, is it not beyond me to assume he lacks understanding of functions, which would also lead me to believe he hasn’t done much practicing within the subject. I apologize that you believe I came off in a harsh way but I promise I did not mean to come off in such a way.

Wish there was a way to report lol. Just looking for answers and this guy must feel threatened by me or something to be this upset over a question.

1 Like

He never actually defined the function in his post, so I don’t know what you are talking about. In your fashion…

I recommend learning the basics of the DevForum before trying to answer questions within the forum, there’s a variety of resources to use that will help greatly with your future endeavours into helping people. (provided below)

If you take these into consideration then good luck!! It’s always nice to see more forum members :slight_smile:

1 Like

Did you fix your rarity issue?

1 Like

I did thank you! I really appreciate you putting links for me to view and read more to expand my knowledge and to hopefully really help people one day!

1 Like

I’m unsure if you’re joking, but I won’t continue this after my post, you may report me if you’d like, aggression towards me is childish though (mostly due to the fact I’ve done nothing wrong and are completely in the right). Beyond this minor “scuffle”, have a nice day. :slight_smile:

Apologies on my part for assuming wrong, I didn’t mean to upset you or degrade you in any fashion.

You can think what you need to off of a post that had a few lines of code, I’m sorry you feel threatened to have to say to someone asking for help that they don’t understand. Which you really do not know me so how would one be able to assume? Just off a simple mistake. Its the same as a spelling mistake.

Seems like your module its not correctly closed at the end, maybe thats the issue why not being able to print it when player clicked.

Probably this is not the best way to achieve the goal, but I would do this to not complicate too much, kinda hardcoded but it works:

The module that holds the rarity table, and perform the check how rare is a number given, will return the name of the rarity:

local rarityChance = {}

rarityChance.RarenessTable = {
	Common = {1,49}, -- 50
	UnCommon = {50,74}, -- 25
	Rare = {75,89}, -- 15
	Ultra = {90,98}, -- 9
	God = {99,100} -- 1

rarityChance.DoRarity = function(number)
	for rarity, rares in pairs(rarityChance.RarenessTable) do
		if number >= rares[1] and number <= rares[2] then
			return rarity

return rarityChance

A server script inside a part with a click detector that will create a random number from 0,100, to ask module what is the rarity of that number:

local rarityChance = require(game:GetService("ServerScriptService"):WaitForChild("rarityChance"))

local PartToClick = game.Workspace.PartToClick

	local randNumb = math.random(1,100)
	local doRarity = rarityChance.DoRarity(randNumb)
	warn(randNumb, "it's:", doRarity)

EDIT: I made a little mistake, I edited it.


Thank you very much for the help!

1 Like

I saw the error, fixed it right away lol!

1 Like

Use math.random and make it check if its between these numbers like

local pet = math.random(100,1)
if pet =<50 and pet => 25 then 
-- give a pet that has a chance between these numbers
1 Like

May I ask how do people have pets display at like 0.00005%

Make it from 1 to 1000 so if you make it check if its 1 then it will be 0.1 chance

1 Like

There’s a tutorial for this in the Devforum, it is called “Weighted Chance” system.


Glad you fixed your issue.

May I recommend looking into weighted probability? That way, you have more control and fine-tuning over percentage proability rather than having to use a range* of values instead.

For example, the psuedocode could look like this:

local rarityModule = {}

local weights = 
  ["Common"] = 1,
  ["Uncommon"] = 0.5,
  ["Rare"] = 0.25,
  ["Epic"] = 0.125,
  -- etc., etc.

-- The ratio of Common to Rare is 1:0.25 = 4:1, which means for every 4 Commons you will on average receive one Rare
-- This allows for strong fine-tuning and knowledge of the odds without having to do unnecessary math

local function rarityModule.grabRarity()
  -- do stuff to return a rarity chosen by its weight (you can look this up, it has been implemented many ways in Lua)

return rarityModule

You could even do this to store a lot of information about a given rarity using the table:

local weightsWithExtraInformation = 
  ["Common"] = {weight = 1, value_multiplier = 1, damage_multiplier = 1},
  ["Uncommon"] = {weight = 0.5, value_multiplier = 2.5, damage_multiplier = 2},
  ["Rare"] = {weight = 0.25, value_multiplier = 4, damage_multiplier = 3},
  -- etc., etc.

Ok, so if say I did (1, 10000) would that make it 0.01%?