Table and Math.Random Problems

So im trying to do a random event for a round system and I was testing and came across an error

local Events = {}
function Events.func()
print(“Hello”)
end
function Events.func1()
print(“Hi”)
end
function Events.func3()
print(“eas”)
end

function RandomEvent()
local ChosenEvent = Events[math.random(1,#Events)]
print(ChosenEvent)
end

RandomEvent()

For some reason im getting Math.Random interval is Empty when its not

The table is a dictionary so you can’t do math.random on that
Instead store a table containing the keys and use random on that like this

local keys = {}
for k, _ in pairs(Events) do
	table.insert(keys, k)
end
local randomKey = keys[math.random(#keys)]
local ChosenEvent = Events[randomKey]
2 Likes