Here’s My Code:
local Items = require(game:GetService("ReplicatedStorage"):WaitForChild("Items"))
function module:GetRandomItem(Player)
local Rarity = RandomRarityFunc.PickRandom()
--Just Returns a Random Rarity like "Common", "Uncommon", "Epic", etc
local function Length(Table)
local Counter = 0
for i, v in pairs(Table) do
Counter = Counter + 1
end
return Counter
end
local ItemsOfRarity = {}
for i = 1, Length(Items) do
print(Items)
if Items[i].Rarity == Rarity then
table.insert(ItemsOfRarity, Items[i])
end
end
local RandNum = math.random(1, #ItemsOfRarity)
local Data = {}
table.insert(Data, ItemsOfRarity[RandNum])
table.insert(Data, Rarity)
return Data
end
I am a New Developer (Exp:11 Months) and I am making a Random Item Giving System based on Rarity. This is a small part of that code inside a Module Script. For some reason this Code Dosen’t Work.
Item[1] shows nil when trying to print.
Btw, here’s how the Items module looks like. Its Unfinished