function DataStore.SetKeyValue(N,Q,i)if not N.value then N.value=N:Get({})end N.value[Q]=i end local Q={}do function Q.BeforeInitialGet(i,Q)i.combinedBeforeInitialGet=Q end function Q.BeforeSave(i,Q)i.combinedBeforeSave=Q end function Q.Get(N,Q,i)local B=N.combinedStore:Get({})local V=B[N.combinedName]if not i then if V==nil then V=Q else if N.combinedBeforeInitialGet and not N.combinedInitialGot then V=N.combinedBeforeInitialGet(V)end end end N.combinedInitialGot=true B[N.combinedName]=clone(V)N.combinedStore:Set(B,true)return V end function Q.Set(N,Q,i)local B=N.combinedStore:GetTable({})B[N.combinedName]=Q N.combinedStore:Set(B,i)N:_Update(i)end function Q.Update(i,Q)i:Set(Q(i:Get()))i:_Update()end function Q.OnUpdate(i,Q)if not i.onUpdateCallbacks then i.onUpdateCallbacks={Q}else i.onUpdateCallbacks[#i.onUpdateCallbacks+1]=Q end end function Q._Update(i,Q)if not Q then for Q,N in pairs(i.onUpdateCallbacks or{})do N(i:Get(),i)end end i.combinedStore:_Update(true)end function Q.SetBackup(i,Q)i.combinedStore:SetBackup(Q)end end local i={}i.__index=DataStore
--[[**
	<description>
	Sets the value of the result in the database with the key and the new value. Attempts to get the value from the data store. Does not call functions fired on update.
	</description>

	<parameter name = "key">
	The key to set.
	</parameter>

	<parameter name = "newValue">
	The value to set.
	</parameter>
**--]]
function DataStore:SetKeyValue(key, newValue)
	if not self.value then
		self.value = self:Get({})
	end

	self.value[key] = newValue
end

local CombinedDataStore = {}

do
	function CombinedDataStore:BeforeInitialGet(modifier)
		self.combinedBeforeInitialGet = modifier
	end

	function CombinedDataStore:BeforeSave(modifier)
		self.combinedBeforeSave = modifier
	end

	function CombinedDataStore:Get(defaultValue, dontAttemptGet)
		local tableResult = self.combinedStore:Get({})
		local tableValue = tableResult[self.combinedName]

		if not dontAttemptGet then
			if tableValue == nil then
				tableValue = defaultValue
			else
				if self.combinedBeforeInitialGet and not self.combinedInitialGot then
					tableValue = self.combinedBeforeInitialGet(tableValue)
				end
			end
		end

		self.combinedInitialGot = true
		tableResult[self.combinedName] = clone(tableValue)
		self.combinedStore:Set(tableResult, true)
		return tableValue
	end

	function CombinedDataStore:Set(value, dontCallOnUpdate)
		local tableResult = self.combinedStore:GetTable({})
		tableResult[self.combinedName] = value
		self.combinedStore:Set(tableResult, dontCallOnUpdate)
		self:_Update(dontCallOnUpdate)
	end

	function CombinedDataStore:Update(updateFunc)
		self:Set(updateFunc(self:Get()))
		self:_Update()
	end

	function CombinedDataStore:OnUpdate(callback)
		if not self.onUpdateCallbacks then
			self.onUpdateCallbacks = { callback }
		else
			self.onUpdateCallbacks[#self.onUpdateCallbacks + 1] = callback
		end
	end

	function CombinedDataStore:_Update(dontCallOnUpdate)
		if not dontCallOnUpdate then
			for _, callback in pairs(self.onUpdateCallbacks or {}) do
				callback(self:Get(), self)
			end
		end

		self.combinedStore:_Update(true)
	end

	function CombinedDataStore:SetBackup(retries)
		self.combinedStore:SetBackup(retries)
	end
end

local DataStoreMetatable = {}

DataStoreMetatable.__index = DataStore
