local mod = require(v.ModuleScript) -- v is what the loop iterates
Is it possible to store a function into a variable like this and call mod(parameter)?
I’ve tried different ways, but I don’t know the root of the problem.
for i,v in ipairs(frame:GetChildren()) do
local mod = require(v.ModuleScript)
game.ReplicatedStorage.UpdateStats.OnClientEvent:Connect(function()
Set(v,mod)
end)
end
function Set():
local function Set(v,mod)
v.Cost.Text = "$"..tostring(module:Suffix(mod(plr)))
v.Button.Text = "Upgrade"
local lvl = game.ReplicatedStorage.GetStat:InvokeServer("Mining Speed")
local child = game.ReplicatedStorage.Formulas:FindFirstChild(v.Name)
local list
if child then list = require(child)end
local max = require(game.ReplicatedStorage.Formulas.MaxStats)
if lvl < max[v.Name] and list then
v.Change.Text = list[lvl].." sec --> "..list[lvl+1].." sec"
elseif list then
v.Change.Text = list[lvl].." sec"
v.Button.Text = "Maxed!"
elseif lvl >= max[v.Name] then
v.Button.Text = "Maxed!"
end
end
I’m still not sure what you are trying to do? What do you mean by storing functions in variables? You do it all the time. For example, Set is a variable pointing to a function.
Unless you’re talking about something else? Doesn’t this do what you want it do?
Remember that Lua has first-class functions, and that they are a datatype, first class means they have the same rights as other conventional value (like strings, numbers, etc) in where variables can contain them, they can be passed around as arguments, and can be returned by functions.