While writing the pick module, I came across a bad problem I cannot fix. So basiclly I want to pick a tool based on chance and these tools have tags on them, which is the rarity. When I try to check if value has a tag and try to insert it and print it, it isn’t printing all of the items. It is only printing 1 or 2 when it should be printing like 4 or 5. Here is the module:
local RaritySpawnModule = {}
--//This module will pick tool based on rarity\\--
local WeightedChanceModule = require(script.Parent.Parent.Modules.WeightedChanceModule)
local CS = game:GetService("CollectionService")
--//Tables\\--
local common = {}
local uncommon = {}
local rare = {}
local ultrarare = {}
local tools = {}
local toolTable = {
{"Commontool",25},
{"Uncommontool",20},
{"Raretool",1},
{"UltraRaretool",1}
}
for index,value in pairs(game.ServerStorage. toolFolder:GetChildren()) do
table.insert( tools,value)
end
--//Functions\\--
function RaritySpawnModule.PicktoolBasedOnRarity()
local item = WeightedChanceModule.RandomItem(toolTable)
--//Gets all values in tool table\\--
for index,value in pairs(tools) do
if CS:HasTag(value,"Common") then
table.insert(common,value)
if item == "Commontool" then
local randomCommon = math.random(1,#common)
local commontool = common[randomCommon]
print(commontool.Name.." Has been picked!")
return commontool
end
elseif CS:HasTag(value,"Uncommon") then
table.insert(uncommon,value)
if item == "Uncommontool" then
local randomUncommon = math.random(1,#uncommon)
local uncommontool = uncommon[randomUncommon]
print(uncommontool.Name.." Has been picked!")
return uncommontool
end
elseif CS:HasTag(value,"Rare") then
table.insert(rare,value)
print(unpack(rare)) --Should be printing around 5 items, only prints 2
if item == "Raretool" then
local randomrare = math.random(1,#rare)
local raretool = rare[randomrare]
print(raretool.Name.." Has been picked!")
return raretool
end
elseif CS:HasTag(value,"UltraRare") then
table.insert(ultrarare,value)
print(unpack(ultrarare)) --Only prints 1 value instead of 3
if item == "UltraRaretool" then
local randomultrarare = math.random(1,#ultrarare)
local ultrararetool = ultrarare[randomultrarare]
print(ultrararetool.Name.." Has been picked!")
return ultrararetool
end
end
end
end
return RaritySpawnModule
I have checked every tool tag to see if anything is wrong. Every tag is right where it should be.