Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

plugin:SetSetting() doesn't seem to work?

Asked by 5 years ago
Edited 5 years ago

I'm making a plugin and I'm trying to save a table as a setting. I'm pretty sure you can call :SetSetting() passing a table as a parameter, but it doesn't seem to work. Here's the code:

script.SaveSource.OnInvoke = function(source)
    print("Saving source:",source.Name, "which is a", type(source)) 

    savedSources[source.Name] = source

    print("savedSources is a", type(savedSources), ", list of elements:")
    for i, value in pairs(savedSources) do print(">", i, value) end

    plugin:SetSetting(SETTING_KEY, savedSources)

    local loaded = plugin:GetSetting(SETTING_KEY)
    print("Loaded", loaded, " which is a ", type(loaded))
end

So, savedSources is a table which contains source objects, so I'm attempting to save the savedSources table as a setting for my plugin. But it doesn't seem to be working. Here's what it prints out when I try to save:

Saving source: asdfasdf which is a table
savedSources is a table, list of elements:
> asdfasdf table: 3590481C
Loaded nil  which is a  nil

As you can see, it has loaded nil, even though I have just saved a value.

0
You can only save numbers/strings inside arrays in plugins (although numbers will be converted to strings) https://wiki.roblox.com/index.php?title=API:Class/Plugin/SetSetting mattscy 3725 — 5y
0
Well, that's bad DragonOfWar900 397 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You cannot save tables as values in plugin settings. You can, however, save a string table that is JSON encoded.

    local toSave = HttpService:JSONEncode(savedSources) -- Define HttpService.
    plugin:SetSetting(SETTING_KEY, toSave)

    local Xloaded = plugin:GetSetting(SETTING_KEY)
    local loaded = HttpService:JSONDecode(Xloaded)
Ad

Answer this question