function Datastore.Get(N,C,D)if C==nil or N==nil then _L.Print("\075\101\121 \111\114 \100\097\116\097\115\116\111\114\101 \110\105\108",true)return end if type(N)=="\115\116\114\105\110\103"then if not datastoresCache[N]then datastoresCache[N]={}end if not datastoresCache[N][D]then datastoresCache[N][D]=_L.Services.DataStoreService:GetDataStore(N,D)end N=datastoresCache[N][D]end local Z=0 local j=false local l while Z<maxGetAttempts and l==nil do Z=Z+1 j=pcall(function()l=N:GetAsync(C)end)if not j then wait(.5)end end if Debug then if Z>=maxGetAttempts or l==nil then _L.Print("\067\111\117\108\100 \110\111\116 \103\101\116 \107\101\121 --- \091\098\111\108\100\093"..(C.."\091\047\098\111\108\100\093"),true)end end return l,j end function Datastore.Set(N,C,D,Z)if C==nil or D==nil or N==nil then _L.Print("\075\101\121\044 \118\097\108\117\101\044 \111\114 \100\097\116\097\115\116\111\114\101 \110\105\108",true)return false end if type(N)=="\115\116\114\105\110\103"then if not datastoresCache[N]then datastoresCache[N]={}end if not datastoresCache[N][Z]then datastoresCache[N][Z]=_L.Services.DataStoreService:GetDataStore(N,Z)end N=datastoresCache[N][Z]end local j=0 local l=false repeat j=j+1 l=pcall(function()N:SetAsync(C,D)end)if not l then wait(.5)end until l or j>=maxSetAttempts if Debug then if j>=maxSetAttempts then _L.Print("\070\097\105\108\101\100 \116\111 \115\101\116 \107\101\121 --- \091\098\111\108\100\093"..(C.."\091\047\098\111\108\100\093"),true)end end return l end function Datastore.Update(N,C,D,Z)if C==nil or D==nil or N==nil then _L.Print("\075\101\121\044 \102\117\110\099\116\105\111\110\044 \111\114 \100\097\116\097\115\116\111\114\101 \110\105\108",true)return false end if type(N)=="\115\116\114\105\110\103"then if not datastoresCache[N]then datastoresCache[N]={}end if not datastoresCache[N][Z]then datastoresCache[N][Z]=_L.Services.DataStoreService:GetDataStore(N,Z)end N=datastoresCache[N][Z]end local j=0 local l=false repeat j=j+1 l=pcall(function()N:UpdateAsync(C,D)end)if not l then wait(.5)end until l or j>=maxUpdateAttempts if Debug then if j>=maxUpdateAttempts then _L.Print("\070\097\105\108\101\100 \116\111 \117\112\100\097\116\101 \107\101\121 --- \091\098\111\108\100\093"..(C.."\091\047\098\111\108\100\093"),true)end end return l end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function Datastore.Get(datastore, key, scope)
	--- Sanity check
	if key == nil or datastore == nil then
		_L.Print("Key or datastore nil", true)
		return
	end

	--- If datastore argument is not a datastore obj - find it, and cache it to save memory
	if type(datastore) == "string" then
		if not datastoresCache[datastore] then
			datastoresCache[datastore] = {}
		end
		if not datastoresCache[datastore][scope] then
			datastoresCache[datastore][scope] = _L.Services.DataStoreService:GetDataStore(datastore, scope)
		end
		datastore = datastoresCache[datastore][scope]
	end

	--- Attempt it
	local attempts = 0
	local success = false
	local returnedValue
	--
	while attempts < maxGetAttempts and returnedValue == nil do
		attempts = attempts + 1
		success = pcall(function()
			returnedValue = datastore:GetAsync(key)
		end)
		if not success then
			wait(0.5)
		end
	end

	--- Debug prints
	if Debug then
		if attempts >= maxGetAttempts or returnedValue == nil then
			_L.Print("Could not get key --- [bold]" .. key .. "[/bold]", true)
		end
	end

	--
	return returnedValue, success
end

function Datastore.Set(datastore, key, value, scope)
	--- Sanity check
	if key == nil or value == nil or datastore == nil then
		_L.Print("Key, value, or datastore nil", true)
		return false
	end

	--- If datastore argument is not a datastore obj - find it, and cache it to save memory
	if type(datastore) == "string" then
		if not datastoresCache[datastore] then
			datastoresCache[datastore] = {}
		end
		if not datastoresCache[datastore][scope] then
			datastoresCache[datastore][scope] = _L.Services.DataStoreService:GetDataStore(datastore, scope)
		end
		datastore = datastoresCache[datastore][scope]
	end

	--- Attempt it
	local attempts = 0
	local success = false
	--
	repeat
		attempts = attempts + 1
		success = pcall(function()
			datastore:SetAsync(key, value)
		end)
		if not success then
			wait(0.5)
		end
	until success or attempts >= maxSetAttempts

	--- Debug prints
	if Debug then
		if attempts >= maxSetAttempts then
			_L.Print("Failed to set key --- [bold]" .. key .. "[/bold]", true)
		end
	end

	--
	return success
end

function Datastore.Update(datastore, key, updateFunction, scope)
	--- Sanity check
	if key == nil or updateFunction == nil or datastore == nil then
		_L.Print("Key, function, or datastore nil", true)
		return false
	end

	--- If datastore argument is not a datastore obj - find it, and cache it to save memory
	if type(datastore) == "string" then
		if not datastoresCache[datastore] then
			datastoresCache[datastore] = {}
		end
		if not datastoresCache[datastore][scope] then
			datastoresCache[datastore][scope] = _L.Services.DataStoreService:GetDataStore(datastore, scope)
		end
		datastore = datastoresCache[datastore][scope]
	end

	--- Attempt it
	local attempts = 0
	local success = false
	--
	repeat
		attempts = attempts + 1
		success = pcall(function()
			datastore:UpdateAsync(key, updateFunction)
		end)
		if not success then
			wait(0.5)
		end
	until success or attempts >= maxUpdateAttempts

	--- Debug prints
	if Debug then
		if attempts >= maxUpdateAttempts then
			_L.Print("Failed to update key --- [bold]" .. key .. "[/bold]", true)
		end
	end

	--
	return success
end
