How to find same variable in all keys in a data store

Hello I’m trying to make something like that: There is a table data and this data will get stored by globally for every key. Every key is global and there will be hundreds or thousands of keys. And I’m trying to check is there a key that has same table data with my table variable. If is there I will return a variable in the key’s table.

The issue is I don’t know how to check all keys in a short time.

I tried to look other forums and other topics and I found something called ListKeysAsync(). But I can’t find how to use it and how can I access the table after checking keys

By the way this is my current script. It is a module script.

local DataStoreService = game:GetService("DataStoreService")
local Data = DataStoreService:GetOrderedDataStore("Pre-Alpha")

local questions = {}

function questions.decide(list)
	local success, Error = pcall(function()
		
	end)
	
	if Error then
		warn(Error)
	end
end

return questions

The list variable on the script is function parameter. I want check this list for every key to find same

1 Like

I know this isn’t what you’re asking but it seems that you want to make a script to check if a player played in the “Pre-Alpha” stage. In which case it’d be easier to award a badge and check if it’s present in the player.

Besides that, since you have a global datastore just save a table of the UserId rather than using each UserId as a key for a tuple. That way you can just iterate through the table to check if the key is present.

2 Likes

I’m trying to make a akinator game that tries to guess roblox games. And each key is for that roblox games. And the tables in that keys is for questions and answers. When player answered questions i was trying to make this function check existing keys to find what roblox game is it.

1 Like

What’s your format for the save?

2 Likes

If you mean table format it is like this:

exampleForGameTable = {
["gameID"] = 0
["gameName"] = "A"

["Questions"] = 
{
["1"] = "Yes"
["2"] = "No"
["3"] = "No"
["4"] = "Yes"
}
}

exampleForAnsweredQuestions = {
["1"] = "Yes"
["2"] = "No"
["3"] = "No"
["4"] = "Yes"
}


1 Like

Right so you have thousands of keys each corresponding to the data. You will have to pcall GetAsync for every tuple in order to check if the table data matches. Instead, why not save all the experience data into a single tuple? That way you will only have to call GetAsync once.

2 Likes

But I need to update a game table data or I need to add a new game to table data. This will be automaticly. For example when someone select a game and game cant guess it, the game will add this game automaticly to the data store and game will set questions to the player’s answers.

So how can I update or add a new table variable in a table without changing or losing other variables?

1 Like

table.insert and update the datastore?

2 Likes

Thank you I will try this.

But I have a question. When this will happen in some other servers at the same time wont it override some data before saving?

MemoryStoreService and cross-server communication with MessagingService will solve your issues. If you aren’t too concerned about the saving rate then turn off UseCache

1 Like