Hello! I’ve been trying to make a chance system. But in the function part, it says table was expected but got nil. Please help!

Module Script:

local Chance = {}
local Shapes = {
---[[Commons]]---
["Ball"] = .5;
["Part"] = .5;
["Cylinder"] = .5;
["Wedge"] = .5;
["Corner"] = .5
}
function GetShapes(Shapes) -- Table Nil?
local Weight = 0
for i, Pick in pairs(Shapes) do
Weight += (Pick * 10)
end
local random_num = math.random(1, Weight)
Weight = 0
for Prize, Pick in pairs(Shapes) do
Weight += (Pick * 10)
if Weight >= random_num then
warn(`Won {Prize}`)
break
end
end
end
print(GetShapes())
return Chance

You put “Shapes” as a parameter but never send it.

function GetShapes(Shapes)

print(GetShapes())

Instead rename the parameter

function GetShapes(atable)

and send the table to the function

print(GetShapes(Shapes))

local Chance = {}
local Shapes = {
---[[Commons]]---
["Ball"] = .5;
["Part"] = .5;
["Cylinder"] = .5;
["Wedge"] = .5;
["Corner"] = .5
}
function GetShapes(atable) -- Table Nil?
local Weight = 0
for i, Pick in pairs(atable) do
Weight += (Pick * 10)
end
local random_num = math.random(1, Weight)
Weight = 0
for Prize, Pick in pairs(atable) do
Weight += (Pick * 10)
if Weight >= random_num then
warn(`Won {Prize}`)
break
end
end
end
print(GetShapes(Shapes))
return Chance