Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

2 comments

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

0

Well, that's bad

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.