I am trying to add something to player’s inventory that I made and [8] is the selected item [1] should be rarity of the item but it just gets the first item from the roll [RNG Game]
for i = 1, 8 do
--wait()
--remotes:WaitForChild("PlaySound"):FireClient(player)
table.insert(Table, chanceList.getRandomIndex(selectChance))
end
giveNewChance(player, Table[8][1], Table[8][2], Table[8][3])
print(Table)
return Table
end
Ensure that “chanceList.getRandomIndex(selectChance)” returns a table with [1] being rarity and [2] being the item; otherwise, it will always insert the first item from the roll, causing the issue.
This is how you should imprement my recommendation:
for i = 1, 8 do
local result = chanceList.getRandomIndex(selectChance)
if type(result) == "table" and result[1] and result[2] then
table.insert(Table, result)
else
warn("Invalid result from chanceList.getRandomIndex(selectChance)")
end
end
giveNewChance(player, Table[8][1], Table[8][2], Table[8][3])
print(Table)
return Table