How to get random value from table?

Hello, i’m trying to get random value from this table
local dogs = {"1269231654", "1269231654", "45447637"}

Soo far i tried:
local image = table[math.random(1, #dogs)] however this returns nil instead image ID.

Any other ideas?

33 Likes
local image = table[math.random(1, #dogs)] 

You need to used dogs as a table instead of an undefined value.

local dogs = {"1269231654", "1269231654", "45447637"}
local image = dogs[math.random(1, #dogs)] -- return one of the values from the dogs table
82 Likes

Thanks! It worked, sorry i’m kinda new to playing with tables.

11 Likes

It’s cool I think I also made the same mistake when I was new to coding lol. Anyways happy coding!

14 Likes