Saving Addon Settings

I’m trying to save the settings of my addon but I’m not sure how to. Below is my current config file, as well as my command file.

Commands



-- Local Functions --
local function CheckBooleanFunc( input )
	if(input == "on") then // so if the command is !ras chat on
	   return true
	elseif(input == "off") then
	   return false
	end
end

local function CheckNumberFunc( input )
	if ( type(tonumber(input)) == "number" ) then
		if ( tonumber(input) >= 0 ) then
			return tonumber(input)
		elseif ( tonumber(input) < 0 ) then
			return '1'
		end
	end
end

-- Enable-Disable Features & Delays | Usage: !ras [function] [on/off] OR !ras [function] [delay] --
hook.Add( "PlayerSay", "RASChatCommands", function( callingPly, text, public )
	local text = string.lower( text )
	local text = string.Explode( " ", text )

	if ( text[1] == "!ras" ) then
			if ( text[2] == "on" ) then
				RAS.Settings.AntiSpamming = true //Change das value.
				RAS.ChatPrint( "Anti-Spam has been enabled by "..callingPly:Nick() )
				RAS.Log( "Enabled by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "off" ) then
				RAS.Settings.AntiSpamming = false //Change das value
				RAS.ChatPrint( "Anti-Spam has been disabled by "..callingPly:Nick() )
				RAS.Log( "Disabled by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "chat" ) then
				RAS.Settings.Chat.Enabled = CheckBooleanFunc( text[3] )
				RAS.ChatPrint( "Chat spam protection has been set to "..text[3].."!" )
				RAS.Log( "Chat Protection set to "..text[3].." by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "props" ) then
				RAS.Settings.Prop.Enabled = CheckBooleanFunc( text[3] )
				RAS.ChatPrint( "Prop spam protection has been set to "..text[3].."!" )
				RAS.Log( "Prop Protection set to "..text[3].." by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "sents" ) then
				RAS.Settings.Sent.Enabled = CheckBooleanFunc( text[3] )
				RAS.ChatPrint( "Scripted Ents spam protection has been set to "..text[3].."!" )
				RAS.Log( "Scripted Ent Protection set to "..text[3].." by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "effects" ) then
				RAS.Settings.Effect.Enabled = CheckBooleanFunc( text[3] )
				RAS.ChatPrint( "Effect spam protection has been set to "..text[3].."!" )
				RAS.Log( "Effect Protection set to "..text[3].." by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "ragdolls" ) then
				RAS.Settings.Ragdoll.Enabled = CheckBooleanFunc( text[3] )
				RAS.ChatPrint( "Ragdoll spam protection has been set to "..text[3].."!" )
				RAS.Log( "Ragdoll Protection set to "..text[3].." by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "vehicles" ) then
				RAS.Settings.Vehicle.Enabled = CheckBooleanFunc( text[3] )
				RAS.ChatPrint( "Vehicle spam protection has been set to "..text[3].."!" )
				RAS.Log( "Vehicle Protection set to "..text[3].." by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "npc" ) then
				RAS.Settings.Npc.Enabled = CheckBooleanFunc( text[3] )
				RAS.ChatPrint( "NPC spam protection has been set to "..text[3].."!" )
				RAS.Log( "NPC Protection set to "..text[3].." by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "chatdelay" && tonumber(text[3]) ~= nil ) then
				RAS.Settings.Chat.Delay = CheckNumberFunc(text[3])
				RAS.ChatPrint( "Chat spam delay is set to "..text[3].." seconds!" )
				RAS.Log( "Chat Protection delay set to "..text[3].." seconds by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "propdelay" && tonumber(text[3]) ~= nil ) then
				RAS.Settings.Prop.Delay = CheckNumberFunc(text[3])
				RAS.ChatPrint( "Prop spam delay is set to "..text[3].." seconds!" )
				RAS.Log( "Prop Protection delay set to "..text[3].." seconds by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "sentdelay" && tonumber(text[3]) ~= nil ) then
				RAS.Settings.Sent.Delay = CheckNumberFunc(text[3])
				RAS.ChatPrint( "Scripted Ent spam delay is set to "..text[3].." seconds!" )
				RAS.Log( "Scripted Ent Protection delay set to "..text[3].." seconds by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "effectdelay" && tonumber(text[3]) ~= nil ) then
				RAS.Settings.Effect.Delay = CheckNumberFunc(text[3])
				RAS.ChatPrint( "Effect spam delay is set to "..text[3].." seconds!" )
				RAS.Log( "Effect Protection delay set to "..text[3].." seconds by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "ragdolldelay" && tonumber(text[3]) ~= nil ) then
				RAS.Settings.Ragdoll.Delay = CheckNumberFunc(text[3])
				RAS.ChatPrint( "Ragdoll spam delay is set to "..text[3].." seconds!" )
				RAS.Log( "Ragdoll Protection delay set to "..text[3].." seconds by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "vehicledelay" && tonumber(text[3]) ~= nil ) then
				RAS.Settings.Vehicle.Delay = CheckNumberFunc(text[3])
				RAS.ChatPrint( "Vehicle spam delay is set to "..text[3].." seconds!" )
				RAS.Log( "Vehicle Protection delay set to "..text[3].." seconds by "..callingPly:Nick() )
				return ''
			elseif ( text[2] == "npcdelay" && tonumber(text[3]) ~= nil ) then
				RAS.Settings.Npc.Delay = CheckNumberFunc(text[3])
				RAS.ChatPrint( "NPC spam delay is set to "..text[3].." seconds!" )
				RAS.Log( "NPC Protection delay set to "..text[3].." seconds by "..callingPly:Nick() )
				return ''
			end
		end
end)



Config



RAS.Chat = {}
RAS.Prop = {}
RAS.Sent = {}
RAS.Effect = {}
RAS.Ragdoll = {}
RAS.Vehicle = {}
RAS.Npc = {}
RAS.Settings = {}

// The RAS system is enabled by default
RAS.Settings.AntiSpamming = true

// Chat RAS Settings
RAS.Settings.Chat = {}
RAS.Settings.Chat.Enabled = true
RAS.Settings.Chat.Delay = 1

// Prop RAS Settings
RAS.Settings.Prop = {}
RAS.Settings.Prop.Enabled = true
RAS.Settings.Prop.Delay = 1

// Scripted Ents RAS Settings
RAS.Settings.Sent = {}
RAS.Settings.Sent.Enabled = true
RAS.Settings.Sent.Delay = 1

// Effects RAS Settings
RAS.Settings.Effect = {}
RAS.Settings.Effect.Enabled = true
RAS.Settings.Effect.Delay = 1

// Ragdoll RAS Settings
RAS.Settings.Ragdoll = {}
RAS.Settings.Ragdoll.Enabled = true
RAS.Settings.Ragdoll.Delay = 1

// Vehicle RAS Settings
RAS.Settings.Vehicle = {}
RAS.Settings.Vehicle.Enabled = false
RAS.Settings.Vehicle.Delay = 1

// NPC RAS Settings
RAS.Settings.Npc = {}
RAS.Settings.Npc.Enabled = true
RAS.Settings.Npc.Delay = 1

//Access Settings
RAS.Settings.UserGroups = {
	['owner'] 		= true,
	['superadmin'] 	= true,
	['admin'] 		= true,
	['moderator'] 	= true
}


This is unrelated but that is an awful way to handle chat commands.
You might wanna take a look at this, it should help you making your code more efficient

As for the save part - What do you mean? Can you edit the settings in-game? If not, what exactly do you mean?

Yes, edit the settings in-game.

You can use file.Write and file.Read (Maybe even file.CreateDir, if you have many things to save and you want to separate them) to save and reload settings. (You’re gonna need to have some identifier [e.g. a semicolon] that will seperate the key from the value in your .txt file)
Make sure you only use file commands on the server’s side! You can’t trust a client with data