Is there any way to store functions in a table so you can call them later?

Title, I just want to know if there is a reliable way to store functions in tables so that you can call them via. math.random later but it seems that the functions just fire every time and then they’re kicked out of the table.

I think you want to use Module Scripts since they can store data and functions and can be required later for later use. So you’d want to create a module script and place it in a folder or location you can get it later.

-- // Module Script \\ --
local module = {}

module.functionToExecute = function()
    -- code here
end

return module

Then in a seperate script you require() it and call it’s function

local module = require(game.ReplicatedStorage.ModuleScript)

module.functionToExecute()
6 Likes

really sorry i know I’m bumping an old topic but you can do this
there is probably better ways but this is the most simple

local T = {}

T[1] = function()
–your code
end

1 Like