Table Problems

I have my config being serialized and de-serialized upon the user changing them with chat commands but for some reason I get the following error:

Below is my config file and chat commands file.

Chat Commands



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

local functionsTable = {} -- Create a table containing all functions
functionsTable["enable"] = function( ply )
	if plyHasPerms( ply ) then
		RAS.AntiSpamming = true
		RAS.ChatPrint( "Raindeer Anti-Spam has been enabled by "..ply:Nick() )
		RAS.Log( "Enabled by ".."["..ply:SteamID().."]"..ply:Nick() )
		return ''
	else
		RAS.ChatPrint( "You do not have permission to do this!", ply )
		return ''
	end
end

functionsTable["disable"] = function( ply )
	if plyHasPerms( ply ) then
		RAS.AntiSpamming = false
		RAS.ChatPrint( "Raindeer Anti-Spam has been disabled by "..ply:Nick() )
		RAS.Log( "Disabled by ".."["..ply:SteamID().."]"..ply:Nick() )
		return ''
	else
		RAS.ChatPrint( "You do not have permission to do this!", ply )
		return ''
	end
end

functionsTable["chat"] = function( ply, args )
	if args[1] == "on" then
		if plyHasPerms( ply ) then
			RAS.Settings.Chat.Enabled = true //Change das value.
			RAS.ChatPrint( "Chat anti-spam has been enabled by "..ply:Nick() )
			RAS.Log( "Chat Protection Enabled by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	elseif args[1] == "off" then
		if plyHasPerms( ply ) then
			RAS.Settings.Chat.Enabled = false //Change das value.
			RAS.ChatPrint( "Chat anti-spam has been disabled by "..ply:Nick() )
			RAS.Log( "Chat Protection Disabled by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	end
end

functionsTable["props"] = function( ply, args )
	if args[1] == "on" then
		if plyHasPerms( ply ) then
			RAS.Settings.Prop.Enabled = true
			RAS.ChatPrint( "Prop anti-spam has been enabled by "..ply:Nick() )
			RAS.Log( "Prop Protection Enabled by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	elseif args[1] == "off" then
		if plyHasPerms( ply ) then
			RAS.Settings.Prop.Enabled = false
			RAS.ChatPrint( "Prop anti-spam has been disabled by "..ply:Nick() )
			RAS.Log( "Prop Protection Disabled by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	end
end

functionsTable["sents"] = function( ply, args )
	if args[1] == "on" then
		if plyHasPerms( ply ) then
			RAS.Settings.Sent.Enabled = true
			RAS.ChatPrint( "Scripted Entity anti-spam has been enabled by "..ply:Nick() )
			RAS.Log( "Scripted Entity Protection Enabled by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	elseif args[1] == "off" then
		if plyHasPerms( ply ) then
			RAS.Settings.Sent.Enabled = false
			RAS.ChatPrint( "Scripted Entity anti-spam has been disabled by "..ply:Nick() )
			RAS.Log( "Scripted Entity Protection Disabled by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	end
end

functionsTable["effects"] = function( ply, args )
	if args[1] == "on" then
		if plyHasPerms( ply ) then
			RAS.Settings.Effect.Enabled = true
			RAS.ChatPrint( "Effect anti-spam has been enabled by "..ply:Nick() )
			RAS.Log( "Effect Protection Enabled by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do  not have permission to do this!", ply )
			return ''
		end
	elseif args[1] == "off" then
		if plyHasPerms( ply ) then
			RAS.Settings.Effect.Enabled = false
			RAS.ChatPrint( "Effect anti-spam has been disabled by "..ply:Nick() )
			RAS.Log( "Effect Protection Enabled by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do  not have permission to do this!", ply )
			return ''
		end
	end
end

functionsTable["ragdolls"] = function( ply, args )
	if args[1] == "on" then
		if plyHasPerms( ply ) then
			RAS.Settings.Ragdoll.Enabled = true
			RAS.ChatPrint( "Ragdoll anti-spam has been enabled by "..ply:Nick() )
			RAS.Log( "Ragdoll Protection Enabled by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	elseif args[1] == "off" then
		if plyHasPerms( ply ) then
			RAS.Settings.Ragdoll.Enabled = false
			RAS.ChatPrint( "Ragdoll anti-spam has been disabled by "..ply:Nick() )
			RAS.Log( "Ragdoll Protection Disabled by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	end
end

functionsTable["vehicles"] = function( ply, args )
	if args[1] == "on" then
		if plyHasPerms( ply ) then
			RAS.Settings.Vehicle.Enabled = true
			RAS.ChatPrint( "Vehicle anti-spam has been enabled by "..ply:Nick() )
			RAS.Log( "Vehicle Protection Enabled by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	elseif args[1] == "off" then
		if plyHasPerms( ply ) then
			RAS.Settings.Vehicle.Enabled = false
			RAS.ChatPrint( "Vehicle anti-spam has been disabled by "..ply:Nick() )
			RAS.Log( "Vehicle Protection Disabled by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	end
end

functionsTable["npc"] = function( ply, args )
	if args[1] == "on" then
		if plyHasPerms( ply ) then
			RAS.Settings.Npc.Enabled = CheckBooleanFunc( text[3] )
			RAS.ChatPrint( "NPC anti-spam has been enabled by "..ply:Nick() )
			RAS.Log( "NPC Protection Enabled by".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	elseif args[1] == "off" then
		if plyHasPerms( ply ) then
			RAS.Settings.Npc.Enabled = CheckBooleanFunc( text[3] )
			RAS.ChatPrint( "NPC anti-spam has been enabled by "..ply:Nick() )
			RAS.Log( "NPC Protection Enabled by".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	end
end

functionsTable["chatdelay"] = function( ply, args )
	if ( tonumber( args[1] ) ~= nil ) then
		if plyHasPerms( ply ) then
			RAS.Settings.Chat.Delay = CheckNumberFunc( args[1] )
			RAS.ChatPrint( "Chat anti-spam delay has been set to "..args[1].." second(s)" )
			RAS.Log( "Chat Protection delay set to "..args[1].." second(s) by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	elseif ( tonumber( args[1] ) == nil ) then
		RAS.ChatPrint( "Please supply a number of seconds to set the delay!", ply )
		return ''
	end
end

functionsTable["propdelay"] = function( ply, args )
	if ( tonumber( args[1] ) ~= nil ) then
		if plyHasPerms( ply ) then
			RAS.Settings.Prop.Delay = CheckNumberFunc( args[1] )
			RAS.ChatPrint( "Prop anti-spam delay has been set to "..args[1].." second(s)" )
			RAS.Log( "Prop Protection delay set to "..args[1].." second(s) by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permissions to do this!", ply )
			return ''
		end
	elseif ( tonumber( args[1] ) == nil ) then
		RAS.ChatPrint( "Please supply a number of seconds to set the delay!", ply )
		return ''
	end
end

functionsTable["sentdelay"] = function( ply, args )
	if ( tonumber( args[1] ) ~= nil ) then
--		if plyHasPerms( ply ) then
			PrintTable( RAS.Settings )
			RAS.Settings.Sent.Delay = CheckNumberFunc( args[1] )
			RAS.ChatPrint( "Scripted Entity anti-spam delay has been set to "..args[1].." second(s)" )
			RAS.Log( "Scripted Entity Protection delay set to "..args[1].." second(s) by ".."["..ply:SteamID().."]"..ply:Nick() )
			RAS.SettingsSave()
			return ''
--		else
--			RAS.ChatPrint( "You do not have permissions to do this!", ply )
--			return ''
--		end
	elseif ( tonumber( args[1] ) == nil ) then
		RAS.ChatPrint( "Please supply a number of seconds to set the delay!", ply )
		return ''
	end
end

functionsTable["effectdelay"] = function( ply, args )
	if ( tonumber( args[1] ) ~= nil ) then
		if plyHasPerms( ply ) then
			RAS.Settings.Effect.Delay = CheckNumberFunc( args[1] )
			RAS.ChatPrint( "Effect anti-spam delay has been set to "..args[1].." second(s)" )
			RAS.Log( "Effect Protection delay set to "..args[1].." second(s) by ".."["..ply:SteamID().."]"..ply:Nick() )
			return ''
		else
			RAS.ChatPrint( "You do not have permission to do this!", ply )
			return ''
		end
	elseif ( tonumber( args[1] ) == nil ) then
		RAS.ChatPrint( "Please supply a number of seconds to set the delay!", ply )
		return ''
	end
end

local function CommandFilter( ply, text )
	local args = string.Split( text, " " )
	if args[1] == "!ras" or args[1] == "/ras" then
		local func = functionsTable[args[2]]
		if func then
			table.remove( args, 1 ) -- There's no need to pass on the "ras" part of it, as we only need it here to call the function
			table.remove( args, 1 ) -- There's also no need to pass on the second part of it, as we only need it here to know which function to call exactly
			PrintTable( RAS.Settings )
			func( ply, args ) -- We pass any additional argument for the function to handle
		end
	end
end
hook.Add( "PlayerSay", "CheckForChatRASCommand", CommandFilter )
/*
			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
			RAS.SettingsSave()
		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
}


-- Serialization & De-Serialization of the config file --

--[[
    This method takes the table and converts it into a string before saving it to a file. This needs to be ran every time you change a value in SETTINGS.
]]
function RAS.SettingsSave()
    -- Serialized the config settings and saved it to a variable
	local SettingString = von.serialize(RAS.Settings)

    -- Saves the serialized vON data to the file
    file.Write("ras_data/ras.txt", SettingString)

    RAS.Log("[RAS] Settings Saved!")
end

--[[
    This method opens the file if it exists and converts the string stored into a table. This needs running when the addon initialises.
]]
function RAS.SettingsLoad()
	local SettingString = RAS.Settings
    -- IF the config file exists, then do the loading
    if file.Exists("ras_data/ras.txt", "DATA") then
        -- Reads the serialized vON data from the file
        local ReadFile = file.Read("ras_data/ras.txt", "DATA")

        -- Deserializes the data and puts the data into the settings
        RAS.Settings = von.deserialize(ReadFile)

        RAS.Log("[RAS] Settings Loaded")
    end
end