The game I’m working on uses the BigNum library to store certain data as the numbers go way above the roblox number limit. However it seems like BigNum
s can’t be saved onto an OrderedDataStore.
Full Script
local prefixes = {
[2] = "K", [3] = "M", [4] = "B", [5] = "T", [6] = "q", [7] = "Q",
[8] = "Sx", [9] = "Sp", [10] = "Oc", [11] = "N"
}
local function format(n)
local NewNum
local Str = tostring(n)
local Length = string.len(Str)
local Rounded = tonumber(string.sub(Str, 1, 4))
local PrefixNumber = math.ceil(Length/3)
local prefix = prefixes[PrefixNumber]
if Length >= 4 then -- If it's in the thousands, then format it.
if Length%3 == 1 then
NewNum = tostring(Rounded/1000)..prefix
end
if Length%3 == 2 then
NewNum = tostring(Rounded/100)..prefix
end
if Length%3 == 0 then
NewNum = tostring(Rounded/10)..prefix
end
else
NewNum = n
end
return NewNum
end
local PlayerStatManager = require(game:GetService("ServerStorage").PlayerStatManager)
local Resources = require(game:GetService("ReplicatedStorage").Resources)
local BigNum = Resources:LoadLibrary("BigNum")
local DSS = game:GetService("DataStoreService")
local SkullsDS = DSS:GetOrderedDataStore("SkullDS9")
local SkullsLB = workspace.SkullsLB.LB.LB.SkullsLeaderboard.ScrollingFrame
wait(3)
while true do
-- Datastore variables:
print("Running script")
local smallestFirst = false
local numberToShow = 100
local minValue = 0
local maxValue = 10e50
-- Total Skulls [All-time]
for i,plr in pairs(game.Players:GetChildren()) do
-- if plr.UserId>0 then
if true then
local PlrSkullsStr = PlayerStatManager:getStat(plr, "Total Skulls")
local PlrSkulls = BigNum.fromString64(PlrSkullsStr)
print(format(PlrSkulls))
pcall(function()
SkullsDS:UpdateAsync(plr.UserId,function(oldVal)
--Set new value
return tonumber(PlrSkulls)
end)
end)
end
end
local pages = SkullsDS:GetSortedAsync(smallestFirst, numberToShow, minValue, maxValue)
--Get data
local top = pages:GetCurrentPage()
print(top)
for i, v in pairs(top) do
print(i, v)
end
print(#top)
for i, v in pairs(SkullsLB:GetChildren()) do
if v.Name ~= "UIListLayout" then
v:Destroy()
end
end
for rank, player in ipairs(top) do
print(rank, player)
local userid = player.key
local username = "[Failed To Load]"
local s,e = pcall(function()
username = game.Players:GetNameFromUserIdAsync(userid)
end)
if not s then
warn("Error getting name for "..userid..". Error: "..e)
end
local PlrCard = script.Sample:Clone()
PlrCard.Rank.Text = rank.."."
PlrCard.PlrName.Text = username
PlrCard.Value.Text = tostring(format(player.value))
PlrCard.Parent = SkullsLB
PlrCard.LayoutOrder = rank
PlrCard.Name = rank
end
wait(60)
end
Output
I had tried this same script with normal numbers and it functions perfectly. So I’m just assuming that the problem is BigNums can’t be saved in OrderedDataStores.
Any solutions would be much appreciated!
Thanks, Kipp