# Script keeps changing number in module when I don't want it to

So, I’m making a little luck system and I have the rarities stored in a module, but it keeps changing the number in the module when I don’t want it too

code:

``````local RaritySystem = {}

function Sort()

end

function CheckTable(Table,Key)
for i, v in pairs(Table) do
if v[1] == Key then
return v
end
end
return false
end

function RaritySystem.GetItem(Rarities, List)
local NewList = {}
if List.Luck then
for i, v in pairs(Rarities) do
if (List.Luck * .01) < Rarities[i][2] then
if CheckTable(NewList,Rarities[i][1]) == false then
table.insert(NewList,Rarities[i])
CheckTable(NewList,Rarities[i][1])[2] = Rarities[i][2] / (List.Luck * .01)
else
CheckTable(NewList,Rarities[i][1])[2] = Rarities[i][2] / (List.Luck * .01)
end
end
end;
end
print(NewList)
local RNG = Random.new();
local Counter = 0;
for i, v in pairs(NewList) do
Counter += (1/NewList[i][2])
end;
local Chosen = RNG:NextNumber(0, Counter);
for i, v in pairs(NewList) do
Counter -= (1/NewList[i][2])
if Chosen > Counter then
return NewList[i]
end
end
end

return RaritySystem
``````

DUDE CMON THIS HAPPENS EVERYTIME I USE DEV FORUM. I FOUND IT OUT RIGHT WHEN I POSTED

code:

``````local RaritySystem = {}

function Sort()

end

function RaritySystem.GetItem(Rarities, List)
local NewList = {}
for _, Iv in pairs(Rarities) do
table.insert(NewList,Iv)
end
if List.Luck then
for i, v in pairs(NewList) do
if (List.Luck * .01) < Rarities[i][2] then
NewList[i][2] = NewList[i][2] / (List.Luck * .01)
end
end;
end
print(NewList)
local RNG = Random.new();
local Counter = 0;
for i, v in pairs(NewList) do
Counter += (1/NewList[i][2])
end;
local Chosen = RNG:NextNumber(0, Counter);
for i, v in pairs(NewList) do
Counter -= (1/NewList[i][2])
if Chosen > Counter then
return NewList[i]
end
end
end

return RaritySystem
``````