How to put the save values into a table upon saving?

Hello Developers,
I am Clzxwork a game developer, me and my friends are making a game and our datastore keeps giving us an error. We have been told that

means That’s a warning that basically means that you are sending too many requests to the datastore, causing that error. If you send too many requests (I think it’s like 30+) at a time, it will drop them out of the queue (that request will be ignored). In your code, you are using ‘GetAsync’ way too many times for something you could do in 1 request. Instead of storing different values like that, I strongly recommend that you store all of your data in a table and use your player’s ID as the key. That way, when you need to grab something from the DataStore, you can just index it from when you originally used GetAsync.

But I am terrible at scripting, my scripters said:

Put the save values into a table upon saving

I am clueless on what to do. Please can you all help, thank you so much!

I’m not asking for you to do it, I just need directions.

Script:
message (11).txt (9.8 KB)

Example:

local playerDatas = {}
playerDatas[plr.Name]["Coins"] = 10 -- or get the value from somewhere
playerDatas[plr.Name]["XP"] = 50

In this example if you save playerDatas[plr.Name], this will get saved:

{
["Coins"] = 10
["XP"] = 50
}

Hope that helps.

Sorry for the late reply but for:

{
[“Coins”] = 10
[“XP”] = 50
}

is there anyway to put it in an order so basically for mine I want [“Total Mined”] to be the first leaderstat but it has no order. Please can you help thank you!

-Clzxwork

So you want to insert these to a leaderboard? Assuming that you do from this phrase,

You can just,

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr

local totalMined = Instance.new("IntValue")
totalMined.Parent = leaderstats
totalMined.Name = "Total Mined"
totalMined.Value = playerDatas[plr.Name]["Total Mined"]

If you mean the first thing to show up in leaderstats I think that’s about when you parent these int values to leaderstats folder, for example if you parent this first, it’ll be the first to show up there.