So this is a leaderboard script for top players and modified it with Abbreviations but i cannot seem to pass the Value for the "Gold"(Value in leaderstats) im getting an error saying "Workspace.Leaderboard.GlobalLeaderboardGold.SurfaceGui.Script:75: invalid argument #1 to 'abs' (number expected, got string)" at this line of code: local exp = math.floor(math.log(math.max(1, math.abs(value)),1000)). I've tried multiple ways of adding the value but most of them returned nil. I need to somehow get the value just like in the while loop or something.
-- [ SETTINGS ] --
local StatsName = "Gold" -- Your stats name
local MaxItems = 100 -- Max number of items to be displayed on the leaderboard
local MinValueDisplay = 1 -- Any numbers lower than this will be excluded
local MaxValueDisplay = 10e15 -- (10 ^ 15) Any numbers higher than this will be excluded
local UpdateEvery = 5 -- (in seconds) How often the leaderboard has to update
-- [ END SETTINGS ] --
-- Don't edit if you don't know what you're doing --
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. StatsName)
local SurfaceGui = script.Parent
local Sample = script.Sample
local List = SurfaceGui.Frame.List
local ItemsFrame = List.ListContent.Items
local function GetItems()
local Data = DataStore:GetSortedAsync(false, MaxItems, MinValueDisplay, MaxValueDisplay)
local TopPage = Data:GetCurrentPage()
ItemsFrame.Nothing.Visible = #TopPage == 0 and true or false
for i, v in ipairs(TopPage) do
local UserId = v.key
local Value = v.value
local Username = "[Not Available]"
local Color = Color3.fromRGB(38, 50, 56)
local Success, Error = pcall(function()
Username = game.Players:GetNameFromUserIdAsync(UserId)
end)
if i == 1 then
Color = Color3.fromRGB(255, 215, 0)
elseif i == 2 then
Color = Color3.fromRGB(192, 192, 192)
elseif i == 3 then
Color = Color3.fromRGB(205, 127, 50)
end
local Item = Sample:Clone()
Item.Name = Username
Item.LayoutOrder = i
Item.Values.Number.TextColor3 = Color
Item.Values.Number.Text = i
Item.Values.Username.Text = Username
Item.Values.Value.Text = Value
Item.Parent = ItemsFrame
end
end
while true do
for i, v in pairs(game.Players:GetPlayers()) do
local Stats = v.leaderstats:WaitForChild(StatsName).Value
if Stats then
pcall(function()
DataStore:UpdateAsync(v.UserId, function(Value)
return tonumber(Stats)
end)
end)
end
end
local SuffixList = {"", "K", "M", "B", "T", "Qa", "Qi"}
local function Format(value, idp)
local exp = math.floor(math.log(math.max(1, math.abs(value)),1000))
local suffix = SuffixList[1 + exp] or ("e+" .. exp)
local norm = math.floor(value * ((10 ^ idp) / (1000 ^ exp))) / (10 ^ idp)
return("%.".. idp .. "f%s"):format(norm, suffix)
end
for i, v in pairs(ItemsFrame:GetChildren()) do
if v:IsA("ImageLabel") then
v:Destroy()
end
end
GetItems()
wait()
SurfaceGui.Heading.Heading.Text = StatsName .. " Leaderboard"
List.ListContent.GuideTopBar.Value.Text = Format(StatsName)
List.CanvasSize = UDim2.new(0, 0, 0, ItemsFrame.UIListLayout.AbsoluteContentSize.Y + 35)
wait(UpdateEvery)
end

2 comments
local exp = math.floor(math.log(math.max(1, math.abs(tonumber(value))),1000))
value has no value its a string i need to get the value from StatsName somehow just like its in the While loop i've tried alot of things but i couldn't get it to work