How do I use incrementasync with a dictionary?

I am trying to make a global leaderboard for countries (players select a country, and all players with the same country increment the same value). I have all countries stored in a folder in serverstorage saved as int values (Country name is the int value’s name), and players can increment that int value (I’ve got this part scripted).

I’m stuck at the part where I need to store the countries’ names and values onto a datastore, to later locally fetch that data and display it on a leaderboard (my leaderboard is on a GUI).
First I’m putting all the country names and values onto a table:

local countryData = {}
for _, country in ipairs(countries:GetChildren()) do -- Iterates through all intvalues in the folder
	local countryClicks = country.Value -- Variable containing the int value's clicks
	if countryClicks then -- Prevent errors
		table.insert(countryData, {country, countryClicks}) -- Insert the country name and it's clicks into a table
	end
end

Now, I’m trying to use incrementasync, because the int values in the folder don’t get updated from the datastore, so using updateasync wouldn’t do what I’m trying to do.
But I’m not sure how to get it to work with incrementasync. I can’t make every country name a different key, because I would hit the datastore limit that way (I’ve got 100+ countries). I tried making a table with all countries and values, and using incrementasync with it with a “global key”, but I couldn’t get it to work.

I’m completely stumped, may I get some guidance on what I should look into, what I need to understand to make it work? Thanks in advance.

1 Like