Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I add weight to these tables?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

0
Explain please. songboy50 77 — 5y
0
Bump songboy50 77 — 5y
Ad

Answer this question