What I’m trying to get?:
I’m trying to make a function getrandomobject() but with rarity number value that is inside of that object.
I want that rarity number to be any number. And i aslo don’t want it to choose by for example: Common, rare, extra rare. But i want to get it by number, Like higher number is, there is more chance to that function to choose it.
Then you can create a global loot table inside a ModuleScript or Script which has all the rarity number that you want it to drop. You also have to create a number which is a base number that the rarity number will be ranged. This is a starter table
local GlobalLootTable = {
["item1Rarity"] = {
["BaseRange"] = 10000, -- This number will be used as a range for your math.random() later.
["ChanceTable"] = {
["ItemA"] = 1000, -- 10%
["ItemB"] = 500, -- 5%
["ItemC"] = 1, -- 0.1%
}
}
}
local function getRandomObject()
for ItemName, Chance in pairs(GlobalLootTable["item1Rarity"]["ChanceTable"]) do
local randomNumber = math.random(GlobalLootTable["item1Rarity"]) -- This will allow multiple drops, but each iteration will get its random chance.
if Change <= randomNumber then
print("Drop!" .. ItemName)
do
end
end
@Jacky2804 . I mean that this is my folder:
and the weight value is rarity number. there are rarity number scale from 0-2000 the higher rarity number is chigher chance to choose it from serverscript.
So you can use a Script inside ServerScriptService to loop through that folder to get the value like this
local sectionsFolder = game:GetService("ServerStorage"):FindFirstChild("sections")
for _, child in pairs(sectionsFolder:GetChildren()) do
local childRarity = child:FindFirstChild("weight")
if childRarity == nil then --Guarding
continue
end
print("Rarity!" ,childRarity.Value)
end