function DataStore.Debug(z,...)if Debug then print(...)end end function DataStore._GetRaw(z)if not z.getQueue then z.getQueue={}end if z.getting then z:Debug("\065 \095\071\101\116\082\097\119 \105\115 \097\108\114\101\097\100\121 \105\110 \109\111\116\105\111\110\044 \106\117\115\116 \119\097\105\116 \117\110\116\105\108 \105\116\'\115 \100\111\110\101")local w=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")z.getQueue[#z.getQueue+1]=w w.Event:wait()z:Debug("\065\097\097\110\100 \119\101\'\114\101 \098\097\099\107")return end z.getting=true local w,l=pcall(function()return((z.orderedDataStore:GetSortedAsync(false,1)):GetCurrentPage())[1]end)if not w then z.getting=false error(l)end if l then local w=l.value z:Debug("\109\111\115\116 \114\101\099\101\110\116 \107\101\121",l)z.mostRecentKey=w local b,e=pcall(function()return z.dataStore:GetAsync(w)end)if not b then z.getting=false error(e)end z.value=e else z:Debug("\110\111 \114\101\099\101\110\116 \107\101\121")z.value=nil end for w,l in pairs(z.getQueue)do z:Debug("\114\101\115\117\109\105\110\103 \105\110 \113\117\101\117\101",l)l:Fire()end z.getQueue={}z.haveValue=true z.getting=false end function DataStore._Update(w,z)if not z then for z,l in pairs(w.callbacks)do l(w.value,w)end end w.haveValue=true w.valueUpdated=true end
--Internal functions
function DataStore:Debug(...)
	if Debug then
		print(...)
	end
end

function DataStore:_GetRaw()
	if not self.getQueue then
		self.getQueue = {}
	end

	if self.getting then
		self:Debug("A _GetRaw is already in motion, just wait until it's done")
		local event = Instance.new("BindableEvent")
		self.getQueue[#self.getQueue + 1] = event
		event.Event:wait()
		self:Debug("Aaand we're back")
		return
	end

	self.getting = true

	local success, mostRecentKeyPage = pcall(function()
		return self.orderedDataStore:GetSortedAsync(false, 1):GetCurrentPage()[1]
	end)

	if not success then
		self.getting = false
		error(mostRecentKeyPage)
	end

	if mostRecentKeyPage then
		local recentKey = mostRecentKeyPage.value
		self:Debug("most recent key", mostRecentKeyPage)
		self.mostRecentKey = recentKey
		local success, value = pcall(function()
			return self.dataStore:GetAsync(recentKey)
		end)
		if not success then
			self.getting = false
			error(value)
		end
		self.value = value
	else
		self:Debug("no recent key")
		self.value = nil
	end

	for _, waiting in pairs(self.getQueue) do
		self:Debug("resuming in queue", waiting)
		waiting:Fire()
	end

	self.getQueue = {}
	self.haveValue = true
	self.getting = false
end

function DataStore:_Update(dontCallOnUpdate)
	if not dontCallOnUpdate then
		for _, callback in pairs(self.callbacks) do
			callback(self.value, self)
		end
	end

	self.haveValue = true
	self.valueUpdated = true
end
