How do i abbreviate a leaderboard with datastore2?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to be able to see values such as 1000 = 1k and 1000000 = 1M etc

  2. What is the issue? I cant find any good tutorials that works for my leaderboard

  3. What solutions have you tried so far? I have looked everywhere, i have spent 3-4 hours looking for a good tutorial on how to actually abbreviate a leaderboard on youtube, stackoverflow, scriptinghelpers and the dev forum

Im wondering how i could be able to abbreviate numbers in a leaderboard, also a gui. I have searched alot on the internet but i couldn’t find a good tutorial that fits my leaderboard nor gui. Any help would be greatly appreciated.

Note: I do not have any previous experience in abbreviating a leaderboard or gui, try to keep it as simple as possible :slight_smile: I also have a simplified version of datastore2 https://www.youtube.com/watch?v=FZx0fVqgRIE

1 Like

You won’t need to do it within datastore2, saving their entire value is fine

Once the player joins, you can use a function such as this (maybe copy-pasted from stack overflow :roll_eyes:) to put the values in the leaderstats

function foo(n)
    if n >= 10^6 then
        return string.format("%.2fm", n / 10^6)
    elseif n >= 10^3 then
        return string.format("%.2fk", n / 10^3)
    else
        return tostring(n)
    end
end

So basically

local data = DataStore2("coins", player)
print(foo(data:Get(1000)))
2 Likes

The issue with that from what I can see is that the leaderstats for the coins value in this case for example will be unformatted, there needs to be 2 values for the coins for the actual value and the value in leaderstats for the formatted version, or just a stringvalue with the data formatted, which will require a bit of work to unformat for other uses, the 2nd one would be better probably. Your idea is good, but it can get a bit confusing when you have tons of numbers to abbreviate.

There is a way that @faroutofspace could use which is detailed in this tutorial which is probably a better way to go about this

2 Likes

Is there any way to make it display on the leaderboard as abbreviated form? Because im pretty sure that the tutorial is only for gui’s and if it is i have no clue how i can make it work for my leaderboard as well

Are you using a leaderstats for the gui? All you need to do is set the value of the StringValue to the formatted version

local player = game.Players.LocalPlayer
local stats = player:WaitForChild("leaderstats")
local gems = stats:WaitForChild("Gems")
local text = script.Parent

text.Text = gems.Value
gems:GetPropertyChangedSignal("Value"):Connect(function()
	text.Text = gems.Value
end)

This is my gui that counts the gems, forgot to take the coins gui xD but they all work the same.
Also in the video he does math.random(), how would i do to make it so it increases my coins
whenever i click my gui button and whenever the coins value reaches over 1000 it displays 1k

So you only want to abbreviate a Leaderboard gui? I thought you meant leaderstats haha.

You can basically almost rewrite what he did in his tutorial, a module for the abbreviations and the function to abbreviate, and then in your code


local player = game.Players.LocalPlayer
local stats = player:WaitForChild("leaderstats")
local gems = stats:WaitForChild("Gems")
local text = script.Parent

local numberAbbreviations = require(game.ReplicatedStorage.NumberAbbreviations) --Change with the location of your module script

text.Text = tostring(numberAbbreviations:Abbreviate(val))
gems.Changed:Connect(function(val) -- You can use this for BaseValues
	text.Text = tostring(numberAbbreviations:Abbreviate(val))
end)
1 Like

Im kinda confused, so am i supposed to make a module script with the same code that he did in his video? Im not the worlds best scripter, i have only been scripting for about 3 months xD Cant i just change the number = math.random() to like number = Coins.Value or something like that

You basically make the same modulescript he did yea, then in your code, you jsut make another variable that requires everything in that modulescript and whenever the value of gems changes, run the Abbreviate function, passing the current value of gems as the parameter

1 Like

Ohh, i’ll try that. Thanks :slight_smile: