Accessing offline player's data using DataStore2

You can access the data of an offline player while using the DataStore2 module, but the module itself offers no support at all. If you do want to access it anyways, you have to check how DataStore2 saves the data and then write a custom function.

Below is a function that could possibly work, but it is untested. (Based off of the reply here: How to use DataStore2 - Data Store caching and data loss prevention - #187 by Kampfkarren)

local DataStoreService = game:GetService("DataStoreService")

function getData(userId, name)
	local orderedDataStore = DataStoreService:GetOrderedDataStore(name .. "/" .. userId)
	local dataStore = DataStoreService:GetDataStore(name .. "/" .. userId)

	local pages = orderedDataStore:GetSortedAsync(false, 1)
	local data = pages:GetCurrentPage()
	if data[1] ~= nil then -- Check if you even received an entry
		return dataStore:GetAsync(data[1]) -- Get first entry with first key
	end
	return nil
end
6 Likes