Searching through DataStoreService for specific "word" in table of DataStore

I am wanting to search throughout my entire DataStoreService i.e. the DataStore which holds a bunch of names and details within that name/character. I am wanting to search in the DataStore for all of the characters which have the eye color of Blue, and then print out all of the characters names which have the eye color Blue.

Such as;

local Storage = game:GetService('DataStoreService'):GetDataStore('CADV3_CivilianCharacters')

local data 
	local success, err = pcall(function()
		data = Storage:SetAsync(""..firstname.." "..lastname, {
			PlayerID = LocalPlayer.UserId,
			PlayerName = LocalPlayer.Name,
			FirstName = firstname,
			LastName = lastname,
			Alias = alias,
			Age = age,
			DOB = dob,
			Gender = gender,
			Height = height,
			HairColor = haircolor,
			EyeColor = eyecolor,
			Weight = weight,
			SkinTone = skintone,
			DMVStatus = dmvstatus,
			DriversLicense = driverslicense,
			FirearmLicense = firearmlicense,
			BusinessLicense = businesslicense
		})
	end)

So search “Storage” for those that have EyeColor set to Blue and then return all of the keys/characters which have that eye color.

1 Like

I do not believe you can get everything in a datastore, however, you can store the datastore keys in a separate datastore and from there loop through all of the entries with that key.
Example:

local DataStoreService = game:GetService("DataStoreService")

local keysDatastore = DataStoreService:GetDataStore("keysData")
local keys = datastore:GetAsync("InfoDataKeys") -- Retrieve the info datastore keys

local infoData = DataStoreService:GetDataStore("information") -- Get the info datastore

for _, v in ipairs(keys) do -- Loop through the keys to get the information
      print(v) -- this will print the key
      local info = infoData:GetAsync(v) -- get the info from the informationdatastore using the key in the keysdatastore
      print(info.EyeColor) -- get any piece of information
end

-- Note that you will have to save each key in a separate datastore to loop through them

Hope this made sense!

1 Like

Would it be possible to do this? Or perhaps something similar to this?


local Storage = game:GetService('DataStoreService'):GetDataStore('CADV3_CivilianCharacters')

for _, v in pairs(Storage:GetAsync()) do
        if v.EyeColor == "Blue" then
           print("this is the one")
       end
end
1 Like