GetSortedAsync issue

Ok so i have playerData DataStore that stores like 5 things, i need to GetSortedAsync of only 1 of the 5 things, how do i do that?

Whenever you save a player’s stat, like “A thing”, make sure you also save it in an OrderedDataStore. This way, you can easily sort that stat. But there’s a limit on how many times you can save per minute, so be careful not to overdo it.

Here’s how you do it in code:

lua

local DataStoreService = game:GetService("DataStoreService")
local playerStats = DataStoreService:GetDataStore("playerData")
local thingStats = DataStoreService:GetOrderedDataStore("ThingStats")

function updatePlayerStat(playerId, thingValue)
    local key = tostring(playerId)
    
    -- Saving the stat in playerData
    playerStats:SetAsync(key, {thing = thingValue})
    
    -- Also saving in OrderedDataStore for sorting
    thingStats:SetAsync(key, thingValue)
end

-- Use this function to update stats
-- updatePlayerStat(player.UserId, newThingValue)

Just swap player.UserId and newThingValue with your player’s ID and their new “thing” stat. Keep it simple, and watch out for those limits!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.