Hi, i am trying to make a obby game with a speedrun system but I don’t know how to make a string leaderboard
The time is stored like this:
I tried using tonumber() and string.sub()but didn’t work
PLS HELP
Code:
local sg = script.Parent
local sample = script:WaitForChild("Sample")
local sf = sg:WaitForChild("ScrollingFrame")
local ui = sf:WaitForChild("UI")
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetOrderedDataStore("TimeLb")
wait(5)
while true do
for i,plr in pairs(game.Players:GetChildren()) do
if plr.UserId>0 then
local w = plr.Stats:WaitForChild("Best Time").Value
if w then
pcall(function()
dataStore:UpdateAsync(plr.UserId,function(oldVal)
return tonumber(w)
end)
end)
end
end
end
local smallestFirst = true
local numberToShow = 100
local minValue = 1
local maxValue = 10e30
local pages = dataStore:GetSortedAsync(smallestFirst, numberToShow, minValue, maxValue)
local top = pages:GetCurrentPage()
local data = {}
for a,b in ipairs(top) do
local userid = b.key
local timee = b.value
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 image = game.Players:GetUserThumbnailAsync(userid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
table.insert(data,{username,timee,image})
end
ui.Parent = script
sf:ClearAllChildren()
ui.Parent = sf
for number,d in pairs(data) do
local name = d[1]
local val = d[2]
local image = d[3]
local color = Color3.new(1, 1, 1)
if number == 1 then
color = Color3.new(1,1,0)
elseif number == 2 then
color = Color3.new(0.470588, 0.470588, 0.470588)
elseif number == 3 then
color = Color3.fromRGB(170, 85, 0)
end
local new = sample:Clone()
new.Name = name
new.LayoutOrder = tonumber(number)
new.Image.Image = image
new.Image.Place.Text = "#"..number
new.Image.Place.TextColor3 = color
new.PName.Text = name
new.Value.Text = val
new.Value.TextColor3 = color
new.PName.TextColor3 = color
new.Parent = sf
end
wait()
sf.CanvasSize = UDim2.new(0,0,0,ui.AbsoluteContentSize.Y)
wait(120)
end