#item rng tables
1 messages · Page 1 of 1 (latest)
math.random
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```

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?
;compile
local my_table = {Name = "Steve"}
print(my_table[1])
print(my_table.Name)
Program Output
nil
Steve
._.robbe | lua | lua-5.4.7 | wandbox.org
;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```
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 ?
nabtay_92777 | lua | lua-5.4.7 | wandbox.org

you dont even pass arguments when calling getItem
{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
v[2] wouldnt really work since your table is a dictionary and [index] prob only work for arrays