The set up I mentioned about is a tad different. Let me show you what I mean.
Every player (if you went my method) would have a set up like this:
--The following Player is what *could* be OfficialPogCats Data (Me)
local ExampleOfficialPogCatList = {
["AttemptsAtBattle1"] = 5, --Idk what you store, this is an example
["WinsAtBattle1"] = 2,
["Battle1Rank"] = 1, --This is stored in both Player and Server Datastore below as the "Position" in where they finished.
["AttemptsAtBattle2"] = 7,
["WinsAtBattle2"] = 1,
["Battle2Rank"] = 3821,
}
--My User Id is 648942781 so My key in this example to load this data is 648942781-BattleKey
--The following Player is what *could* be Rumixist Data
local ExampleRumixistList = {
["AttemptsAtBattle1"] = 25, --Idk what you store, this is an example
["WinsAtBattle1"] = 10,
["Battle1Rank"] = 2, --This is stored in both Player and Server Datastore below as the "Position" in where they finished.
["AttemptsAtBattle2"] = 54,
["WinsAtBattle2"] = 21
["Battle2Rank"] = 3,
}
--Your User Id is 852327832 so your key in this example to load this data is 852327832-BattleKey
The Above is how I would set up something like this. That way when the Player wants to search other people, You only have to do something like this:
local PlayerByName = "OfficialPogCat"
local UserID = game.Players:GetUserIdFromNameAsync(PlayerByName)
local Datastore = game:GetService("DataStoreService"):GetDataStore("BattleData")
local PlayerSearchData = Datastore:GetAsync(UserID.."-BattleKey") --Ideally you want to pcall this and do more fancy things. This is an example however.
if PlayerSearchData ~= nil then
--Do whatever you want here
else
print("Player Data is Nil... ")
end
Note: For a system like this you want to make sure that the Player is a Real person, and you also want to add cooldowns to searching. They don’t have to be huge, but if the player spam clicks the button you are going to go above the limits of the Reading data. So make sure you have a cooldown and that before you request to the server to search a person, you make sure the person is real.
Now this doesn’t fix the original problem of the post, which is why we have a Second version Which we can store for the server usage. (Aka this is the one that you would use UpdateAsync() on, and this is the one that you would use for Top 100 award etc. ) An example of the Set up is like this:
local BattleOneExample = {
["Stats"] = { --I guess if you want stats you can.
["Battle1Attempts"] = 173931,
["Battle1Wins"] = 5621,}
["PlayerRanks"] = {
[1] = 648942781, --First Number being the Position they won. Second one being their UserID
[2] = 852327832,
...
}
}
--For example, This key will be ServerBattle1-Key
Now, when we need to Update this data (add another person to the Rank List) we will Do this:
local Datastore = game:GetService("DataStoreService"):GetDataStore("BattleData")
Datastore:UpdateAsync("ServerBattle1-Key", function(OldData)
--Do magic here of changing position
end) --Ideally you want to pcall this and do more fancy things. This is an example however.
I know I just threw out a ton of information for you! So let me know if you have questions! But this is what I would do if I were you in setting up this.
P.S : I know I didn’t directly answer a lot of your questions. Use different keys. Search By rank should use the Server Data, Rank search by Name/ UserId should be done by Personal Data. You should Prevent as many :GetAsync() calls as you can. There is datastore limits and so you need to follow the limits. What I would do is have the Server store the Main Battles list and change it every 15-30 minutes. Then I would have player limits, so a player can only search 3-5 players per minute to get their personal data. (Once they search 3-5 players, there is a cooldown until the next minute happens. It should be a short wait anyways as they would see to view 3-5 players before it)