Convert leaderboard value into M (Millions) and K ( Thousands) Without destroying database

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

  1. What do you want to achieve? Keep it simple and clear!
    I want to convert a number to M’s and K’s. Example: 2.300.000 to 2.3M

  2. What is the issue? Include enough details if possible!
    The database probably gets destroyed by the string value.

  3. What solutions have you thought of so far?
    Adding an alternative int value that can be used for the database

  4. After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

So I wanna change very long values to M’s and K’s, K standing for thousand and M standing for millions. Is this possible though, without killing the database? :slight_smile:

Here is the code that gives money and saves when the user leaves:

game.Players.PlayerAdded:connect(function(player)
     local leaderstats = Instance.new("IntValue")
     leaderstats.Name = "leaderstats"
     local time = Instance.new("IntValue")
     time.Name = "Salary ($)"  --Leaderboard Name
     time.Parent = leaderstats
     leaderstats.Parent = player
     while wait(60*15) do
          AddCash(player)
     end
end)

--Saving Data
game.Players.PlayerRemoving:connect(function(player)
	local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
        local statstorage = player:FindFirstChild("leaderstats"):GetChildren()

        for i =  1, #statstorage do
	     datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
	     print("saved data number "..i)
	
       end
       print("Stats successfully saved")	
end)

--Loading Data
game.Players.PlayerAdded:connect(function(player)
	local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
	
	player:WaitForChild("leaderstats")
	wait(1)
	local stats = player:FindFirstChild("leaderstats"):GetChildren()
	for i = 1, #stats do			
	stats[i].Value = datastore:GetAsync(stats[i].Name)
	print("Found stat number"..i.."")
	end
end)


function AddCash(player)
        player.leaderstats["Salary ($)"].Value = player.leaderstats["Salary ($)"].Value + 125000
        -- I normally have more code here but it's not needed for the issue
end)

Sincerely, ItsMeMathe

Have an existing data value that stores the real number, then have the leaderboard data be the fake string.

Great solution, thank you. It was kind of the idea I had in mind but it’s probably the best method.