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

Hi. I keep getting the error " attempt to call upvalue 'raritys' (a table value)"?

Asked by 6 years ago

If anyone can help i'd be very grateful. :)

local raritys = {
    Common = 5,
    Uncommon = 3,
    Rare = 1,
    Legendary = 0.2
}
local crateInUse = true

local function openCrate(chance)
    if crateInUse == true then
     local items = {}
     local result 
     local frametimes = math.random(20,30)
     for _,Item in pairs(game.ReplicatedStorage.Items:GetChildren()) do
        local rarNumber = raritys(Item.Rarity.Value)
        local times = math.max(rarNumber/chance)
        end
    math.randomseed(tick())

    for num = 1,frametimes+5 do
        local item = items[math.random(#items)]
        local newicon = script.Parent.Unboxing.Inner.Icon:Clone()
        newicon.Visible = true
        newicon.Parent = script.Parent.Unboxing.Inner
        newicon.Image = item.ImageID.Value
        newicon.Position = UDim2.new(0,100*(num-1),0,0)
        if num == frametimes then
            result = item
            crateInUse = false
        end

    end
    end
end


script.Parent.TextButton.MouseButton1Click:Connect(openCrate(2))
0
use [] instead of () abnotaddable 920 — 6y
0
And where do i do that? DevRolizzard 13 — 6y
0
local rarNumber = raritys[Item.Rarity.Value] abnotaddable 920 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

When you have a table, you should index it using []s. When you have a function, you should call it using ().

abnotaddable is correct; the fix is to have local rarNumber = raritys[Item.Rarity.Value] on line 15.

Also, only use math.randomseed once at the top of the script and use up the first math.random() without using its value: math.randomseed(tick()); math.random(). The first random number is rarely different for mildly different seeds.

Ad

Answer this question