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

How to add rarity to my item loading script?

Asked by 3 years ago
local ItemRooms = {}
local Items = {}
local DescCoolDown = false
local LoadEvent = game.ReplicatedStorage.RemoteEvents.LoadEvent

local function LoadItems()
    local ItemFile = game.ReplicatedStorage.Items
    for _, v in pairs(workspace:GetDescendants()) do
        if v:IsA("Model") and v.Name == "ItemRoom" then
            local Item = ItemFile:GetChildren()
            local chosenItem = Item[math.random(1, #Item)]:Clone()
            chosenItem.Parent = v
            chosenItem:MoveTo(v.Pedastol.Position + Vector3.new(0, 4, 0))
            table.insert(ItemRooms, v)
        end
    end
end
LoadItems()
--//ItemDesc.
for _, v in pairs(ItemRooms) do
    local Peadastol = v.Pedastol
    Peadastol.Touched:Connect(function(p)
        if p.Parent:FindFirstChild("Humanoid") and DescCoolDown == false then
            DescCoolDown = true
            for _, x in pairs(v:GetDescendants()) do
                if x:IsA("Model") and game.ReplicatedStorage.Items:FindFirstChild(x.Name) then
                    local GUI = script.DescGUI:Clone()
                    local Desc = x:FindFirstChild("Description")
                    local Player = game.Players:FindFirstChild(p.Parent.Name)
                    GUI.Holder.Description.Text = Desc.Value
                    GUI.Holder.Item.Text = x.Name
                    GUI.Parent = Player.PlayerGui
                    wait(5)
                    GUI:Destroy()
                    DescCoolDown = false
                end
            end
        end
    end)
end

I have an IntValue stored in the item file named "Rarity" and I was wondering if there was a way to make that IntValue change how often different rarity items spawned? I tried making a table that inserts each item with its rarity inside and adding weight but I couldnt quite figure it out... Please help.

Answer this question