Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I pick the top number off an ordered datastore?

Asked by 8 years ago

Say I had OrderedDataStore A, in this code:

local A = game:GetService("DataStoreService"):GetOrderedDataStore("Group Troopers") --Creates my new DataStore

game.Players.PlayerAdded:connect(function (Player)
    if not A:GetAsync(Player.Name) then
        A:SetAsync(Player.Name, [CURRENT TOP NUMBER + 1])
    end
end)

(Assume that I went in the console and made a placeholder with value 0, so that would be the greatest number in the store.)

Where I have [CURRENT TOP NUMBER + 1], I want to script it so that the script will search through the datastore for the HIGHEST NUMBER, then add 1 to it for the new trooper number. How can I go about this?

Thanks in advance, SquirrelOnToast

1
Look up "GetOrderedAsync" <- It loads data even if people arnt in the server ;D MessorAdmin 598 — 8y
0
So I could just set the ids per page to 1, and make a function go through the table checking if it's the end page? Sounds good SquirreIOnToast 309 — 8y

Answer this question