--// GENERAL VARIABLES
local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetOrderedDataStore("test")
local moduleSc = require(game.ReplicatedStorage.Abbreviate)
local dividenumber = 100
--// UI VARIABLES
local UI = script.Parent.SurfaceGui
local basePlayerFrame = UI.BasePlayerFrame
local boardFrame = UI.ScrollingFrame
--// Functions
local function SaveData()
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
local plr_key = "id_" .. player.UserId .. "_Strength"
local Strength = player:FindFirstChild("Strength")
if Strength and typeof(Strength.Value) == "number" then
local success, result = pcall(function()
DataStore:SetAsync(plr_key, math.floor(Strength.Value/dividenumber))
end)
if not success then
warn(result)
end
else
warn("Strength " .. player.Name)
end
end
end
local function getTop10Players()
local isAscending = false
local pageSize = 10
local pages = DataStore:GetSortedAsync(isAscending, pageSize)
local top10 = pages:GetCurrentPage()
local top = {}
for rank, data in ipairs(top10) do
local dataName = data.key
local name = game:GetService("Players"):GetNameFromUserIdAsync(dataName:split('_')[2])
local Strength = data.value
local currentPlayer = { Player = name, Strength = Strength, Rank = rank, }
table.insert(top, rank, currentPlayer)
end
return top
end
local function ClearList()
task.spawn(function()
for _, plrFrame in pairs(boardFrame:GetChildren()) do
if not plrFrame:IsA("Frame") then continue end
plrFrame:Destroy()
task.wait(0.25)
end
end)
end
local function UpdateList()
SaveData()
ClearList()
local top50 = getTop10Players()
task.spawn(function()
for _, plr in ipairs(top50) do
local frame = basePlayerFrame:Clone()
frame.Parent = boardFrame
frame.name.Text = plr.Player
frame.Strength.Text = moduleSc.abbreviate(plr.Strength * dividenumber)
frame.rank.Text = plr.Rank
frame.Visible = true
task.wait(0.25)
end
end)
end
task.spawn(function()
while true do
UpdateList()
for count=5,0,-1 do
script.Parent.Part.SurfaceGui.Count.Text = "Leaderboard Updating In:" .. count .. " seconds!"
task.wait(1)
end
end
end)
DataStoreService: ValueNotNumeric: Sorted datastore values must be integer numbers API: SetAsync, Data Store: test - Studio
20:15:28.882 502: API Services rejected request with error. Error code: 14 Reason: Sorted datastore values must be integer numbers
I multiplied how much I needed and it worked and now I would like to tell you how it works if the player has a strength of 1e30 and I write in the dividend such 1e30 then it shows and when I type 1e40 it does not show is it possible Make it so that it is automatically reduced to the player’s strength
okay so here i added a function that calulcates the scaling factor with the value’s magnitude.
--// GENERAL VARIABLES
local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetOrderedDataStore("test")
local moduleSc = require(game.ReplicatedStorage.Abbreviate)
local function ScaleFactor(value)
local magnitude = math.floor(math.log10(value))
local scale = 10 ^ (magnitude - 2)
return scale
end
--// UI VARIABLES
local UI = script.Parent.SurfaceGui
local basePlayerFrame = UI.BasePlayerFrame
local boardFrame = UI.ScrollingFrame
--// Functions
local function SaveData()
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
local plr_key = "id_" .. player.UserId .. "_Strength"
local Strength = player:FindFirstChild("Strength")
if Strength and typeof(Strength.Value) == "number" then
local scale = ScaleFactor(Strength.Value)
local success, result = pcall(function()
DataStore:SetAsync(plr_key, math.floor(Strength.Value / scale))
end)
if not success then
warn(result)
end
else
warn("Strength " .. player.Name)
end
end
end
local function getTop10Players()
local isAscending = false
local pageSize = 10
local pages = DataStore:GetSortedAsync(isAscending, pageSize)
local top10 = pages:GetCurrentPage()
local top = {}
for rank, data in ipairs(top10) do
local dataName = data.key
local name = game:GetService("Players"):GetNameFromUserIdAsync(dataName:split('_')[2])
local Strength = data.value
local scale = ScaleFactor(Strength)
local currentPlayer = { Player = name, Strength = Strength * scale, Rank = rank }
table.insert(top, rank, currentPlayer)
end
return top
end
local function ClearList()
task.spawn(function()
for _, plrFrame in pairs(boardFrame:GetChildren()) do
if not plrFrame:IsA("Frame") then continue end
plrFrame:Destroy()
task.wait(0.25)
end
end)
end
local function UpdateList()
SaveData()
ClearList()
local top50 = getTop10Players()
task.spawn(function()
for _, plr in ipairs(top50) do
local frame = basePlayerFrame:Clone()
frame.Parent = boardFrame
frame.name.Text = plr.Player
frame.Strength.Text = moduleSc.abbreviate(plr.Strength)
frame.rank.Text = plr.Rank
frame.Visible = true
task.wait(0.25)
end
end)
end
task.spawn(function()
while true do
UpdateList()
for count = 5, 0, -1 do
script.Parent.Part.SurfaceGui.Count.Text = "Leaderboard Updating In:" .. count .. " seconds!"
task.wait(1)
end
end
end)