Rarity System [Need Help]

Hello, I am pretty new to roblox scripting like truly trying to learn it. I have been trying to make a rarity system as I had used a module script. I had set the module script up like such:

local rarityChance = {}

function Rarity = {
Uncommon = 50,
Common = 25,
Rare = 15,
Ultra = 5,
God = 1,
}

return rarityChance

I know there is something wrong when I try to call my Module Script.

The concept was you walk to your block click it with the Click Detector function and then your script is inside. Once clicked it would choose a random rarity but i’m stuck at showing the table and not being able to get it as a percentage.

2 Likes

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

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

Roblox Engine API Reference | Roblox Creator Documentation

1 Like

I know the basics of scripting in roblox. I have made games and such just nothing super crazy front page stuff. Just stuck on certain ways to go about the code I guess is the best way to describe it. I have made my code work I just take like 9 years, so I thought id ask for some extra help. Thanks for the reply!

1 Like

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.

2 Likes

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

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

PartToClick.ClickDetector.MouseClick:Connect(function()
	local randNumb = math.random(1,100)
	local doRarity = rarityChance.DoRarity(randNumb)
	warn(randNumb, "it's:", doRarity)
end)

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

2 Likes

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