Is there anyway to show text with OrderedDatastore?

Is it possible to get the data from ODS and place it on some text? And how would I be able to make it work?

Of course it’s possible. This is how game leaderboards work!

You might want to take a look at this article. There is an example code at the bottom!

Yes I know about that. Mostly OrderedDatastore is used for leaderboards. But I am trying to place it onto GUI objects like a TextLabel.

The example code prints every key-value pair. Just place it in a text label instead, what is the problem?

If a player has a specific amount of coins and I want that to update, I dont want a list of players for that.

OrderedDataStores are still DataStores.

Use GetAsync. Here: GlobalDataStore:GetAsync()

I tried already to use GetAsync. it would not work the way I needed it to work.

You need to use GetSortedAsync with the parameters indicated to get the specific range in the amount needed least.

Use a for loop to take the value and key out for every table in the returned table, which came from GetCurrentPage.

And finally, wrap them in a pcall to catch the errors while calling a datastore. It is too risky, you know, we are getting asynchronous methods a lot. It may prevent the script from running.

local DataStoreService = game:GetService("DataStoreService")
local RebirthsDataStore = DataStoreService:GetOrderedDataStore("Rebirths")

local s, e = pcall(function()
    local range = RebirthsDataStore:GetSortedAsync(false, 10, 1, math.huge) -- Ascends or not, how many players to show up, least rebirths, most rebirths
    local list = range:GetCurrentPage() -- The list according to range variable

    for rank, rebirths in ipairs(list) do -- Get rank and rebirths in order
        -- Text labels, colors ...
    end
end)

You could implement the rank and value into the text label.

So this essentially would only show for one player?

roses are red violets are blue

ordereddatastores don’t support strings but tables do

I know datastores store tables. I could use the regular datastore system and be on my way, but I do not want to show the leaderboard on the top right corner.

Opposite.

Ordered data stores don’t accept tables, but integers.

Isnt getting the current page listing data (Like meaning showing a list of player)? I looked at the API and that is what is said. I want a specific value from a player not really a list.

Yeah, they accept tables. Look at the API here: DataStorePages | Roblox Creator Documentation

Let me make an example for you. You didn’t understand at all what I meant by that. Correct me if my grammar didn’t make sense to you.

And also, I mistakenly said strings, but it only accepts integers.

local DataStoreService = game:GetService("DataStoreService")
local Tutorial = DataStoreService:GetOrderedDataStore("Tutorial")

game:BindToClose(function()
    for i, players in pairs(game:GetService("Players"):GetPlayers()) do
	    local s, e = pcall(function()
		    Tutorial:SetAsync(players.UserId, {1123123, 4324235})
	    end)

        if not s then
            print(e)
        end
    end
end)

This will print out an error that says arrays are not allowed. They don’t accept tables; they just return a sub-table of the page that belongs to the player key and value. But you actually save an integer, not a table. I mean, value couldn’t be a table.

Always.

If it was only to accept strings, in order for it to format into my textLabel, wouldn’t I have to use tostring?

i know what you mean, my point is ordered datastore doesn’t store strings.

If only you would mention you want a string before you made this post.

So you want to store a string but cannot do it with ordered data stores? Make a table for that and get the string from it. You want to get it for only one player. So use GetAsync.

local list = {
    [1] = "Take this string out of the table."
}

And put together the scripts.

local number = Tutorial:GetAsync(player.UserId) --pcall

if list[number] then
    game.Workspace.Part.SurfaceGui.TextLabel.Text = list[number]
end
1 Like