How to make it choose different type of rarity?

Hello! I have this rarity system which works. However, it only returns one value so for example, if I get common, It’ll keep returning common. Please help!

Local Script

local rs = game:GetService("ReplicatedStorage")
local folder = rs:WaitForChild("Shapes", 5)

local Spawner = workspace:WaitForChild("Spawner")
local Chance = require(rs:WaitForChild("Chance"))

local gui = script.Parent
local Button = gui.TextButton

local Rarity = {Chance.PickRarity("Rarities")}

Button.MouseButton1Down:Connect(function()
	print(Rarity)
end)

Module Script

local Chance = {}

local Rarities = {
	Common = 0, -- 60% chance
	Rare = 0.6, -- 30% chance
	Legendary = .9, -- 10% chance
	--Mythic = 0.99, -- 1% chance
}



function Chance.PickRarity()
	local Index = math.random()
	local HighestRarity = "Common"

	for RarityName, Value in pairs(Rarities) do
		if Index >= Value and Value >= Rarities[HighestRarity] then
			HighestRarity = RarityName
		end
	end

	return HighestRarity
end

return Chance

It’s because you are not picking a new rarity each time, you are just printing the first rarity that gets picked.

You need to be calling Chance.PickRarity within the MouseButton1Down

Button.MouseButton1Down:Connect(function()
    local Rarity = {Chance.PickRarity("Rarities")}
	print(Rarity)
end)

Wow, I can’t believe that I didn’t thought of that smh. Thanks for the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.