So, I’m attempting to make a game, and to keep my code clean and easily editable I’m using tables, which I have used many times, and I haven’t had a problem like this before.
My problem is that printing the table returns all 3 values, but trying to get one of the values with math.random()
returns nil.
local EndScenarios = {
["Cancelled"] = {["Text1"] = 'T1'; ["Text2"] = 'T2'; ["Text3"] = 'T3'};
["NFT"] = {["Text1"] = 'T1'; ["Text2"] = 'T2'; ["Text3"] = 'T3'};
["HotTub"] = {["Text1"] = 'T1'; ["Text2"] = 'T2'; ["Text3"] = 'T3'};
}
function CallDad(Player)
if Player.Data.Money.Value >= 10000000 then return true, EndScenarios[math.random(1, #EndScenarios)] end
return false, nil
end
Printing out the # of the table returns 0, and as a result, breaks math.random()
error:
01:07:26.246 ServerScriptService.Data_Main:437: invalid argument #2 to 'random' (interval is empty) - Server - Data_Main:437