Hello, so I have this script that should display the leaderstat value. It works for my number value stat but not my String value stat. Any help?
-- [ SETTINGS ] --
local StatsName = "Time"
local MaxItems = 100
local MinValueDisplay = 1
local MaxValueDisplay = 10e15
local UpdateEvery = 60
-- [ END SETTINGS ] --
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard1" .. 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(0, 0, 0)
local Success, Error = pcall(function()
Username = game.Players:GetNameFromUserIdAsync(UserId)
end)
if i == 1 then
Color = Color3.fromRGB(170, 0, 255)
elseif i == 2 then
Color = Color3.fromRGB(68, 0, 103)
elseif i == 3 then
Color = Color3.fromRGB(49, 0, 74)
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
for i, v in pairs(ItemsFrame:GetChildren()) do
if v:IsA("ImageLabel") then
v:Destroy()
end
end
GetItems()
wait()
List.ListContent.GuideTopBar.Value.Text = StatsName
List.CanvasSize = UDim2.new(0, 0, 0, ItemsFrame.UIListLayout.AbsoluteContentSize.Y + 35)
wait(UpdateEvery)
end