I have a game where I'm using a script to format large numbers to a more readable format with abbreviations like "K" for thousands, "M" for millions, "B" for billions, etc. However, I've noticed that the script is not correctly converting 1,000B to 1T in the game's leaderstats. Strangely, the number formatting seems to be working fine in the GUI that shows how many clicks and other items the player has. The problem only seems to occur in the leaderstats. I'm now looking for help to figure out what might be causing this problem and how I can solve it.
#[UNSOLVED] Number formatting script not converting 1,000B to 1T in leaderstats
5 messages · Page 1 of 1 (latest)
the leaderstats script:
local function abbreviateNumber(n)
if n >= 1e15 then return string.format("%.1f%s", n/1e15, "Qu") end
if n >= 1e12 then return string.format("%.1f%s", n/1e12, "T") end
if n >= 1e9 then return string.format("%.1f%s", n/1e9, "B") end
if n >= 1e6 then return string.format("%.1f%s", n/1e6, "M") end
if n >= 1e3 then return string.format("%.1f%s", n/1e3, "K") end
return tostring(n)
end
local DataStoreService = game:GetService("DataStoreService")
local config = script:WaitForChild("datastore_config")
local myDataStore = DataStoreService:GetDataStore("$Data$!"..config:FindFirstChild("DataVersion").Value)
local saving = config:FindFirstChild("Saving")
local autoSave = config:FindFirstChild("AutoSave")
local function create_table(plr)
local player_stats = {}
for _, folder in pairs(script:FindFirstChild("Plr"):GetChildren()) do
if folder:IsA("Folder") then
print(folder)
for _, stat in pairs(plr:FindFirstChild(folder.Name):GetChildren()) do
player_stats[stat.Name.." "..folder.Name] = abbreviateNumber(stat.Value)
end
end
end
return player_stats
end
local function saveData(plr)
local player_stats = create_table(plr)
local succes, err = pcall(function()
local key = plr.UserId.."'s' Data"
myDataStore:SetAsync(key, player_stats)
end)
if succes then
print("Saved Data Correctly!")
else
warn(err)
end
end
continuation:
game.Players.PlayerAdded:Connect(function(plr)
local key = plr.UserId.."'s' Data"
local data = myDataStore:GetAsync(key)
print(data)
for _, folder in pairs(script:FindFirstChild("Plr"):GetChildren()) do
if folder:IsA("Folder") then
local fc = folder:Clone()
fc.Parent = plr
if saving.Value == true then
for _, item in pairs(fc:GetChildren()) do
if data then
item.Value = data[item.Name.." "..folder.Name]
continue
else
warn("There is no data!")
continue
end
end
end
end
while autoSave.Value > 0 do
task.wait(autoSave.Value * 60)
saveData(plr)
print("Saved", data)
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
if saving.Value == true then
saveData(plr)
end
end)
[UNSOLVED] Number formatting script not converting 1,000B to 1T in leaderstats
You could use BigNum module