Help with plugin:SetSetting() and GetSetting()?

I’m making a plugin for notes, and I want them to save through plugin:SetSetting() and plugin:GetSetting() how would I do this?

Heres what I have already, it doesnt work:

Save.MouseButton1Up:Connect(function()
	
	local CurrentTextboxText = ""
	
	plugin:GetSetting(CurrentTextboxText)
	plugin:SetSetting(CurrentTextboxText, true)
	
	Saved.Visible = true
	
	task.wait(5)
	
	Saved.Visible = false
	
end)

Load.MouseButton1Up:Connect(function()
	
	local CurrentTextboxText = ""
	
	local Save = plugin:GetSetting(CurrentTextboxText)
	
	if Save then
		
		TextBox.Text = CurrentTextboxText
		
	end
	
end)
function plugin:SetSetting(string Key, variant value)
-- Set a setting using a key and set the value of the key in the second argument
function plugin:GetSetting(string Key)
-- Retreive a plugin setting value from the requested key

From the looks of it, you’re setting the Key for the plugin setting as the user’s text, which is a bad idea considering many different keys will be created because the text may not always be the same.

You should be doing this:

Save.MouseButton1Up:Connect(function()
	local CurrentTextboxText = "" -- Set this as the user's text
	plugin:SetSetting("UserNotes", CurrentTextboxText) -- the key is "UserNotes" and the value are the notes itself
	
	Saved.Visible = true
	task.wait(5)
	Saved.Visible = false
end)

Load.MouseButton1Up:Connect(function()
	local Save = plugin:GetSetting("UserNotes") -- get the user's notes from the key
	TextBox.Text = Save or "" -- if the user saved something before, load it, if not, then leave it blank
end)

That’s odd, I tried you script and saved my notes, then I went to a different place and pressed load, nothing happened.

Whenever I press load the textbox has no text.

Is the CurrentTextboxText being written to? Like is it being updated to contain the TextBox’s Text? Or is it still just ""?

If it’s not the former, then do:

local CurrentTextboxText = TextBox.Text

It only returns ""
charrrrrr

OHHH, sorry, I just realized that CurrentTextboxText is not being set to anything.

1 Like