Rarity system where rare drops are too common

Basically, I’ve made a rarity system in which a variety of different rarities for ingredients would spawn. However, for some reason, the rarer types are way too common for their given rates. Silver and gold spawning almost all the time

[“Nothing”] = 1,
[“Silver”] = 0.2,
[“Gold”] = 0.1,
[“Ruby”] = 0.02,
[“Diamond”] = 0.005

‘’'lua
function spawndata.pick(rarityTable)
local totalweight = 0
local array = {}

for i,v in pairs(rarityTable) do
	totalweight += v
	array[i] = v
end

local random = Random.new()
local rnd = random:NextNumber(0,totalweight)
local selected = "Nothing"
local accumulatedweight = 0


for i,v in pairs(array) do
	accumulatedweight += v
	if rnd <= accumulatedweight then
		selected = i

		break
	end

end

return selected

end
‘’’

I did try to limit spawns using conditional statements but they were somehow bypassed. Using count and making a conditional statement according to the count for the block below doesn’t work as the ingredients still return with rarities above the limit (count)