I have multiple functions that I want it to be called randomly in my script. However, when I actually insert it inside the table, the function starts to run and I can`t find a way to stop it. I am kind of thinking to do it like this.
local function mission1() --Run end local function mission2() --Run end local function mission3() --run end local missionTable = {mission1,mission2,mission3) --Somehow the function runs in this line as ordered, which is unwanted because it takes so long for every function to finish running. local pickedMission = math.random(1,#missionTable) missionTable[pickedMission]
. However, when I use this code, the function starts to run when I am inserting the function into the table. Is there a way to call these functions without having to run when inserting into the code?
I could also think of this way, but this looks very inefficient and overwhelming if I have tons of function to pick from.
local function mission1() --Run end local function mission2() --Run end local function mission3() --run end local missionPicked = math.random(1,3) if missionPicked == 1 then mission1() elseif missionPicked == 2 then mission2() elseif missionPicked == 3 then mission3() end