How to save a table with plugin

Im trying to save a table through a plugin, but theres one issue; my table have functions, which json does not support of

local data = plugin:GetSetting("data")
print(data)
--[[
{
[1] = {}
[2] = {}
-- ... and so on
}
]]

any ideas on how to save tables?

Are the functions supplied by the user, or did you define them? If they are defined by you, simply keep a dictionary of the functions, and save the key which contains the function you want to save. Upon loading index the dictionary with the key.

local functions = {
    func1 = function()
        -- 
    end,
    func2 = function()
        --
    end
}

local savedFunctions = {"func1", "func2"}

what do you mean by “supplied by the user or did you define them”

Where are the functions defined, did you write them yourself as part of your plugin code, or are they coming from somewhere else? Show me a sample function and how the plugin receives it basically.

local function load(x)
	return plugin:GetSetting(x)
end

local function decode(x)
	return HttpService:JSONDecode(x)
end

local CommandData = decode(load('CommandData')) or {}

this?

thats smart, i will try this

Summary

This text will be hidden

wait, then how do i load the actual data (the user can make changes with the variable and then saves it)

This probably isn’t possible because Luau doesn’t support dumping or loading of arbitrary bytecode, as thats how I would’ve done this if it was possible

1 Like

i solved it by using modulescripts