So I making a plugin called ScriptBoard and I don’t know how to save my script snippets as idk how to use plugin:SetSetting correctly
local toolbar = plugin:CreateToolbar("ScriptBoard")
local desc = "Open's up the clipboard which you can use to copy, paste scripts!"
local button = toolbar:CreateButton("Open ScriptBoard",desc,"rbxassetid://rbxassetid://9068459387")
local help = toolbar:CreateButton("Info","Opens information UI","rbxassetid://8693322638")
local widgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float,
false,
false,
200,
300,
200,
300
)
local Back = script.Parent.UIS.Back
local Code = script.Parent.UIS.Code
local Clipwid = plugin:CreateDockWidgetPluginGui("ScriptBoard", widgetInfo)
Clipwid.Title = "ScriptBoard"
Clipwid.Name = "ScriptBoard"
Back.Parent = Clipwid
local info = script.Parent.UIS.Info
button.Click:Connect(function()
Clipwid.Enabled = not Clipwid.Enabled
end)
help.Click:Connect(function()
if info.Parent == script.Parent.UIS then
info.Parent = game.CoreGui
else
info.Parent = script.Parent.UIS
end
end)
-- below this is store system
local function SerializeCode(code,t,n)
return {
[n] = {
Text = t,
Name = n}
}
end
local function DeserializeCode(data)
local c = Code:Clone()
c.Parent = Back.ClipboardF
c.Name = data.Name
if data.Text ~= "" then
c:Destroy()
else
c.CPreview.Text = data.Text
c.CPreview.TextColor3 = settings().Studio["Text Color"]
c.CPreview.BackgroundColor3 = settings().Studio["Background Color"]
c.CName.Text = data.Name
end
end
for i,v in pairs(plugin:GetSetting("Codes")) do
DeserializeCode(v)
end
local function Update(typ)
repeat
wait()
until Back:FindFirstChild("ClipboardF") ~= nil
for i,child in pairs(Back:WaitForChild("ClipboardF"):GetChildren()) do
if child:IsA("Frame") then
local cp = child.CPreview
local cn = child.CName
if typ == 1 then
plugin:SetSetting("Codes",SerializeCode(child,cp.Text,cn.Text))
else
plugin:SetSetting("Codes",SerializeCode(child,"",cn.Text))
end
end
end
end
Back.ClipboardF.ChildAdded:Connect(function()
Update(1)
print(plugin:GetSetting("Codes"))
end)
Back.ClipboardF.ChildRemoved:Connect(function()
Update(2)
end)
I’ve never used it before but it seems that you’ll need to make a system to make multiple keys. Right now you’re just overriding the same key called “Codes”. If you don’t want multiple keys, you can probably store all the snippets in one table and save it to a single key.
I’m not able to test it, but maybe this will give you some ideas at least. Basically instead of saving each snippet to the key “Codes”, you put the serialized snippet into a table I made called “CodesTable”, then after each snippet you add, it saves the CodesTable of all the snippets to the plugin so that if they leave, it’ll be saved. I also added a part at the top that uses GetSetting to get the table that was saved from the last session and updates the CodesTable.
-- below this is store system
local CodesTable = {} --Table of all of the snip tables
local Codes = plugin:GetSetting("Codes") --Load CodesTable from the last session, if it has been saved before
if Codes then
CodesTable = Codes
end
local function SerializeCode(code,t,n)
local NewTable = {
[n] = {
Text = t,
Name = n}
}
table.insert(CodesTable, NewTable)
end
local function DeserializeCode(data)
local c = Code:Clone()
c.Parent = Back.ClipboardF
c.Name = data.Name
if data.Text ~= "" then
c:Destroy()
else
c.CPreview.Text = data.Text
c.CPreview.TextColor3 = settings().Studio["Text Color"]
c.CPreview.BackgroundColor3 = settings().Studio["Background Color"]
c.CName.Text = data.Name
end
end
for i,v in pairs(plugin:GetSetting("Codes")) do
DeserializeCode(v)
end
local function Update(typ)
repeat
wait()
until Back:FindFirstChild("ClipboardF") ~= nil
for i,child in pairs(Back:WaitForChild("ClipboardF"):GetChildren()) do
if child:IsA("Frame") then
local cp = child.CPreview
local cn = child.CName
if typ == 1 then
SerializeCode(child,cp.Text,cn.Text) --Serializes and adds it to CodesTable
plugin:SetSetting("Codes", CodesTable) --Saves CodesTable with SetSetting
else
SerializeCode(child,"",cn.Text)
plugin:SetSetting("Codes", CodesTable)
end
end
end
end
Back.ClipboardF.ChildAdded:Connect(function()
Update(1)
print(plugin:GetSetting("Codes"))
end)
Back.ClipboardF.ChildRemoved:Connect(function()
Update(2)
end)