Hello guys so basically i want this code to be able to support decimals how would i accomplish this here is the code below
local Items = {
{"Pig",1},
{"Dog",5},
{"Cat",99},
}
local TotalWeight = 0
for _,ItemData in pairs(Items) do
TotalWeight = TotalWeight + ItemData[2]
end
local function chooseRandomItem()
local Chance = math.random(1,TotalWeight)
local Counter = 0
for _,ItemData in pairs(Items) do
Counter = Counter + ItemData[2]
if Chance <= Counter then
return ItemData[1]
end
end
end
for i=1,100 do
wait()
print(chooseRandomItem())
end
Thanks for reading this, Hope you can help.

1 comment
What do you mean by "support decimals"?