Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I add weight to these tables?

I have multiple four folders filled with their own items. Common, Uncommon, Rare, and Legendary. I want to implement the weights into the "BeltRarities" table. I'm not sure if I would do something like

{{Common, CommonWeight], {Uncommon, UncommonWeight}}

or something but when I tried this I think I must have done it incorrectly.

local CommonWeight = 75
local UncommonWeight = 50
local RareWeight = 25
local LegendaryWeight = 5
local TotalWeight = 0

Button.MouseButton1Click:Connect(function()
    print("Opened Package")
    local Common = CommonBelts[math.random(#CommonBelts)]
    local Uncommon = UncommonBelts[math.random(#UncommonBelts)]
    local Rare = RareBelts[math.random(#RareBelts)]
    local Legendary = LegendaryBelts[math.random(#LegendaryBelts)]
    local BeltRarities = {Common, Uncommon, Rare, Legendary}
    local Belts = {BeltRarities[math.random(#BeltRarities)]}
    for i,v in pairs(Belts) do......

1 answer

This is what I used for my weighted table. [I used it for a crate unboxing system]

HERES THE WEIGHTED TABLE [Module Script]

local module = {

	["Common"] = {

	["Cost"] = 250,

	["TestItems"] = {

		["Test1"] = {25},

		["Test2"] = {25},

		["Test3"] = {25},

		["Test4"] = {25}

		}

	}

}

  

return module

NOW HERES THE WEIGHTED SELECTION! [I used mine in a regular script but im sure it could possibly be used in other types of scripts]

local Module = require(RS:WaitForChild("ModuleScript"))
local Data = Module["Common"]
local Cost = Data["Cost"]
local Items = Data["TestItems"]

local TotalWeight = 0
for i,v in pairs(Items) do
	TotalWeight = TotalWeight + v[1]
end

Let me know if this helped!

2 comments

0

Explain please.

0

Bump

This discussion is preserved as it was. New answers, comments, and votes are closed.