#item rng tables

1 messages · Page 1 of 1 (latest)

olive tinsel
#

help

cold elbow
#

math.random

olive tinsel
#
local Items = require(game.ReplicatedStorage.Items)

local possibleItems = {
    {Name = "Funtime Juice",2, Price = 400, Rarity = "Insane", Description = "Crazy juice for a funtime"},
    {Name = "Not So Fun Juice",5, Price = 4000, Rarity = "Strange", Description = "Sad juice for a reflection at life"},
    {Name = "CRAZY Juice",6, Price = 12000, Rarity = "Crazy", Description = "Crazy juice for a CRAZY person"},
    {Name = "Did he Juice",8, Price = 35000, Rarity = "Didhelicious", Description = "Did he order that juice?"},
    {Name = "Dr Did he respect him Juice",9, Price = 50000, Rarity = "Edp", Description = "No he didnt juice for a cool time!"}
}

local function getItem (itemName, itemPrice, itemRarity, itemDescription)
    for i, v in pairs(possibleItems) do
        local rng = math.random(1, v[2])
        if rng == 1 and v[2] >= rng then
            return {
                itemName = itemName[v[1]],
                itemPrice = itemPrice[v[3]],
                itemRarity = itemRarity[v[4]],
                itemDescription = itemDescription[v[5]]
            }
        end
    end
    local iteminfo = {}
    table.insert(iteminfo, itemName, itemPrice, itemRarity, itemDescription)
    return iteminfo
end

while task.wait(3) do
    local itemdata = getItem()
    
    print(itemdata)
end```
cold elbow
olive tinsel
#

13:37:16.683 ServerScriptService.Script:13: invalid argument #2 to 'random' (number expected, got nil) - Server - Script:13

#

lol

#

i made this script with pure memory

#

so im not sure

#

why its erroring

#

i make it so it gets the v[2] which is like 2,3,4,5,6 and does a math . random

#

to get the rarity

#

why is it nil?

cold elbow
#

;compile

local my_table = {Name = "Steve"}
print(my_table[1])
print(my_table.Name)
fringe pebbleBOT
#
Program Output
nil
Steve

olive tinsel
#

;compile

local Items = require(game.ReplicatedStorage.Items)

local possibleItems = {
    {Name = "Funtime Juice",2, Price = 400, Rarity = "Insane", Description = "Crazy juice for a funtime"},
    {Name = "Not So Fun Juice",5, Price = 4000, Rarity = "Strange", Description = "Sad juice for a reflection at life"},
    {Name = "CRAZY Juice",6, Price = 12000, Rarity = "Crazy", Description = "Crazy juice for a CRAZY person"},
    {Name = "Did he Juice",8, Price = 35000, Rarity = "Didhelicious", Description = "Did he order that juice?"},
    {Name = "Dr Did he respect him Juice",9, Price = 50000, Rarity = "Edp", Description = "No he didnt juice for a cool time!"}
}

local function getItem (itemName, itemPrice, itemRarity, itemDescription)
    for i, v in pairs(possibleItems) do
        local rng = math.random(1, v[2])
        if rng == 1 and v[2] >= rng then
            return {
                itemName = itemName[v[1]],
                itemPrice = itemPrice[v[3]],
                itemRarity = itemRarity[v[4]],
                itemDescription = itemDescription[v[5]]
            }
        end
    end
    local iteminfo = {}
    table.insert(iteminfo, itemName, itemPrice, itemRarity, itemDescription)
    return iteminfo
end

while task.wait(3) do
    local itemdata = getItem()
    
    print(itemdata)
end```
fringe pebbleBOT
#
Program Output
/opt/wandbox/lua-5.4.7/bin/lua: prog.lua:1: attempt to index a nil value (global 'game')
stack traceback:
prog.lua:1: in main chunk
[C]: in ?

cold elbow
olive tinsel
#

man

#

this hard

#

do i do

cold elbow
#

you dont even pass arguments when calling getItem

olive tinsel
#
{Name = "Funtime Juice",weight = 2, Price = 400, Rarity = "Insane", Description = "Crazy juice for a funtime"},```
#

omg

#

i just saw that

#

thank you

#
while task.wait(3) do
    local itemdata = getItem()
    itemdata(itemdata.itemName, itemdata.Prce, itemdata.itemRarity, itemdata.itemDescription)
    
    print(itemdata)
end```
#

is this ok

lyric lance
olive tinsel
#

yeah i fixed it

#

it turns out since v[2] is already a key

#

it would be easier to just do