Attributes load and save plugin return index nil

Script works only there is one thing to improve by loading the atributes

I need to save the atributes changed in the script how to do it for plugin

2 Likes

Are you looking for Plugin:GetSetting and SetSetting?

1 Like

Ye how to implement on atributes to save the atributes

1 Like

[masage deleted]

1 Like
--local plugin = plugin

local stylesframe = script.Parent.Parent.Parent.AutoProperties.main.settings.styles.dstyles

local DarkModeImg = false
local DarkModeAuto = true
local DarkMode = true

local Dark_Mode_On = stylesframe:GetAttribute("DarkModeOn")
local Auto_Enabled = stylesframe.adarkmodeauto.toggle.dot:GetAttribute("enabled")
local Dark_Mode = stylesframe.bdarkmode.toggle.dot:GetAttribute("enabled")

local module = {
	save = function()
		print("saving data... | auto properties")
		task.wait(5)

		local success, err = pcall(function()
			plugin:SetSetting(DarkModeImg, Dark_Mode_On)
			plugin:SetSetting(DarkModeAuto, Auto_Enabled)
			plugin:SetSetting(DarkMode, Dark_Mode)
		end)

		if success then
			print("data saved | auto properties")
		else
			warn("failed to save data: " .. err .."| auto properties")
		end
	end,


	load = function()
		print("loading data... | auto properties")
		task.wait(2)

		local success, err = pcall(function()
		Dark_Mode_On = plugin:GetSetting(DarkModeImg)
		Auto_Enabled = plugin:GetSetting(DarkModeAuto)
		Dark_Mode = plugin:GetSetting(DarkMode)
end)
		if success then
			print("data saved | auto properties")
		else
			warn("failed to load data: " .. err .."| auto properties")
		end
	end,
}

return module

pls help me it keeps saying failed to load data: PluginDebugService.user_auto properties.rbxmx.auto properties.Assets.modules.savingdata.data:37: attempt to index nil with 'GetSetting'| auto properties

and failed to save data: PluginDebugService.user_auto properties.rbxmx.auto properties.Assets.modules.savingdata.data:19: attempt to index nil with 'SetSetting'| auto properties

i dont know what i do frong but it doesnt save and load the atributes.

1 Like

iirc ModuleScript’s environments does not include the plugin API, so you would have to either do:

local plugin: Plugin = plugin or getfenv().PluginManager():CreatePlugin()

or pass your plugin variable from your main script. From my vague memory, it would be better to do the latter because republishing a local plugin with the first method does not clear up any registered key (i.e plugin:CreateToolbar) and would give you an override error.

Do test this behavior as it’s been a while since I’ve worked on a plugin.

1 Like

That API crash studio with the new ui cuz it’s depraced

1 Like

Seems like a pretty bad bug, and considering there is no replacement at the moment, stick with the non-beta version of studio for now.

From the post you’ve linked, it seems only the first method crashes. Have you tried passing in the plugin variable from the script itself?

1 Like

Like script.parent.plugin I tried earlier but it seems not to working but not on this script I can test out tomorrow

1 Like

You can also do

local plugin = script:FindFirstAncestorOfClass("Plugin")

I figured it out I fixed and the plugin thing works

local plugin = script:FindFirstAncestorOfClass("Plugin")

local stylesframe = script.Parent.Parent.Parent.AutoProperties.main.settings.styles.dstyles

local DarkModeImg = "darkmodeimg"
local DarkModeAuto = "darkmodeauto"
local DarkMode = "darkmode"



local module = {
	save = function()
		
		local Dark_Mode_On = stylesframe:GetAttribute("DarkModeOn")
		local Auto_Enabled = stylesframe.adarkmodeauto.toggle.dot:GetAttribute("enabled")
		local Dark_Mode = stylesframe.bdarkmode.toggle.dot:GetAttribute("enabled")
		print("saving data... | auto properties")
		task.wait(5)

		local success, err = pcall(function()
			plugin:SetSetting(DarkModeImg, Dark_Mode_On)
			plugin:SetSetting(DarkModeAuto, Auto_Enabled)
			plugin:SetSetting(DarkMode, Dark_Mode)
			print(Auto_Enabled)
		end)

		if success then
			print("data saved | auto properties")
		else
			warn("failed to save data: " .. err .."| auto properties")
		end
	end,


	load = function()
		print("loading data... | auto properties")
		task.wait(2)

		local success, err = pcall(function()
		local Dark_Mode_On_Data = plugin:GetSetting(DarkModeImg)
		local Auto_Enabled_Data = plugin:GetSetting(DarkModeAuto)
		local Dark_Mode_Data = plugin:GetSetting(DarkMode)
		print(Auto_Enabled_Data)
			if Dark_Mode_On_Data ~= nil then
				stylesframe:SetAttribute("DarkModeOn", Dark_Mode_On_Data)
			end

			if Auto_Enabled_Data ~= nil then
				stylesframe.adarkmodeauto.toggle.dot:SetAttribute("enabled", Auto_Enabled_Data)
			end

			if Dark_Mode_Data ~= nil then
				stylesframe.bdarkmode.toggle.dot:SetAttribute("enabled", Dark_Mode_Data)
			end
end)
		if success then
			print("data loaded | auto properties")
		else
			warn("failed to load data: " .. err .."| auto properties")
		end
	end,
	
	reset = function()
		plugin:ClearSettings()
	end,
}

return module

Only here I think it runs the load function if ranbefore key is false not true

One thing it checked if things aren’t nil but I have alot atributes to save is there s way to do it on one loop or something so the script don’t be much lines



local module = require(script.data)



local RAN_BEFORE_KEY = "RanBefore"
local didRunBefore = plugin:GetSetting(RAN_BEFORE_KEY)

if didRunBefore == true then
	print("Welcome back!")
	module.load()
else
	plugin:SetSetting(RAN_BEFORE_KEY, true)
	print("nice that you installed auto properties if you encounter iseus or see buggs pls report it trough the feedback app")
end

while true do
	wait(300)
	module.save()
end

In some way it save Roblox toolbox settings in the settings file I checked replace for scripts but didn’t find one is that normal for local plugins

{ "RanBefore":true}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.