Please help me correct these errors.
DataStoreService: MaxValueInvalid: MaxValue and MinValue must be integers. API: GetSortedAsync, Data Store: RebirthsLeaderboardRelease
DataStoreService: MaxValueInvalid: MaxValue and MinValue must be integers. API: GetSortedAsync, Data Store: EggsHatchedLeaderboardRelease
DataStoreService: MaxValueInvalid: MaxValue and MinValue must be integers. API: GetSortedAsync, Data Store: RobuxSpentDataRelease1
DataStoreService: MaxValueInvalid: MaxValue and MinValue must be integers. API: GetSortedAsync, Data Store: TotalGemsLeaderboardRelease1
DataStoreService: MaxValueInvalid: MaxValue and MinValue must be integers. API: GetSortedAsync, Data Store: TotalClicksLeaderboardRelease
DataStoreService: MaxValueInvalid: MaxValue and MinValue must be integers. API: GetSortedAsync, Data Store: TimePlayedLeaderboardRelease
DataStoreService: MaxValueInvalid: MaxValue and MinValue must be integers. API: GetSortedAsync, Data Store: RebirthsLeaderboardRelease
DataStoreService: MaxValueInvalid: MaxValue and MinValue must be integers. API: GetSortedAsync, Data Store: EggsHatchedLeaderboardRelease
DataStoreService: MaxValueInvalid: MaxValue and MinValue must be integers. API: GetSortedAsync, Data Store: RobuxSpentDataRelease1
DataStoreService: MaxValueInvalid: MaxValue and MinValue must be integers. API: GetSortedAsync, Data Store: TotalGemsLeaderboardRelease1
DataStoreService: MaxValueInvalid: MaxValue and MinValue must be integers. API: GetSortedAsync, Data Store: TotalClicksLeaderboardRelease
DataStoreService: MaxValueInvalid: MaxValue and MinValue must be integers. API: GetSortedAsync, Data Store: TimePlayedLeaderboardRelease
Here’s my script:
local LeaderboardService = {}
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
--// Variables
local Leaderboards = Workspace:WaitForChild("Main"):WaitForChild("Important"):WaitForChild("Leaderboards")
local Shared = ReplicatedStorage:WaitForChild("Shared")
local Modules = Shared:WaitForChild("Modules")
local Template = script:WaitForChild("Template")
local UpdateInterval = 120
--// Modules
local FormatNumber = require(Modules.FormatNumber)
local LayoutUtil = require(Modules.LayoutUtil)
local TimerUtil = require(Modules.TimerUtil)
function LeaderboardService:GetValue(Player, Type)
if Player:FindFirstChild("PlayerData") and Player:FindFirstChild("PlayerData"):FindFirstChild("Stats") then
for i, v in ipairs(Player.PlayerData.Stats:GetChildren()) do
if v.Name == Type then
return v.Value
end
end
end
end
function LeaderboardService:ShortenNumber(n)
return n ~= 0 and n ~= nil and math.floor(math.log(n) / math.log(1.0000000001)) or 0
end
function LeaderboardService:ConvertToTime(seconds)
if seconds < 3600 then
return TimerUtil:ToMS(seconds)
elseif seconds >= 3600 and seconds < 86400 then
return TimerUtil:ToHMS(seconds)
elseif seconds >= 86400 then
return TimerUtil:ToDHMS(seconds)
end
end
function LeaderboardService:ClearBoard(Scroll)
for i,v in ipairs(Scroll:GetChildren()) do
if v:IsA("Frame") then
v:Destroy()
end
end
end
function LeaderboardService:UpdateBoards()
for i, leaderboard in ipairs(Leaderboards:GetChildren()) do
coroutine.wrap(function()
local leaderboardType = leaderboard.LeaderboardType.Value
local dataStoreName = leaderboard.DataStoreName.Value
local isRanked1 = ""
local Success, Data = pcall(function()
return DataStoreService:GetOrderedDataStore(dataStoreName):GetSortedAsync(false, 100, 0, math.huge)
end)
if Success then
local Page = Data:GetCurrentPage()
self:ClearBoard(leaderboard.MainPart.SurfaceGui.Scroll)
for Rank, StoredData in ipairs(Page) do
local template = Template:Clone()
template.Rank.Text = "loading..."
template.Amount.Text = "loading..."
template.PlayerName.Text = "loading..."
local PlayerUsername = nil
pcall(function()
PlayerUsername = Players:GetNameFromUserIdAsync(StoredData.key)
end)
if PlayerUsername then
template.PlayerName.Text = PlayerUsername
else
template.PlayerName.Text = "failed to load"
end
if leaderboardType ~= "TimePlayed" then
template.Amount.Text = FormatNumber.FormatCompact(math.floor(StoredData.value ~= 0 and (1.0000000001^StoredData.value) or 0))
else
local secondsPlayed = math.floor(StoredData.value ~= 0 and (1.0000000001^StoredData.value) or 0)
template.Amount.Text = self:ConvertToTime(secondsPlayed)
end
if leaderboardType == "TotalClicks" then
if Rank == 1 then
template.Rank.TextColor3 = Color3.fromRGB(255, 203, 14)
template.Amount.TextColor3 = Color3.fromRGB(255, 203, 14)
template.PlayerName.TextColor3 = Color3.fromRGB(255, 203, 14)
local humanoidDescription = Players:GetHumanoidDescriptionFromUserId(StoredData.key)
if humanoidDescription then
leaderboard.NPC.Humanoid:ApplyDescription(humanoidDescription)
end
isRanked1 = PlayerUsername
elseif Rank == 2 then
template.Rank.TextColor3 = Color3.fromRGB(134, 168, 191)
template.Amount.TextColor3 = Color3.fromRGB(134, 168, 191)
template.PlayerName.TextColor3 = Color3.fromRGB(134, 168, 191)
local humanoidDescription = Players:GetHumanoidDescriptionFromUserId(StoredData.key)
if humanoidDescription then
leaderboard.NPC2.Humanoid:ApplyDescription(humanoidDescription)
end
elseif Rank == 3 then
template.Rank.TextColor3 = Color3.fromRGB(162, 113, 113)
template.Amount.TextColor3 = Color3.fromRGB(162, 113, 113)
template.PlayerName.TextColor3 = Color3.fromRGB(162, 113, 113)
local humanoidDescription = Players:GetHumanoidDescriptionFromUserId(StoredData.key)
if humanoidDescription then
leaderboard.NPC3.Humanoid:ApplyDescription(humanoidDescription)
end
elseif Rank <= 3 then
template.Rank.TextColor3 = Color3.fromRGB(255, 255, 255)
template.Amount.TextColor3 = Color3.fromRGB(255, 255, 255)
template.PlayerName.TextColor3 = Color3.fromRGB(255, 255, 255)
end
else
if Rank == 1 then
template.Rank.TextColor3 = Color3.fromRGB(255, 203, 14)
template.Amount.TextColor3 = Color3.fromRGB(255, 203, 14)
template.PlayerName.TextColor3 = Color3.fromRGB(255, 203, 14)
elseif Rank == 2 then
template.Rank.TextColor3 = Color3.fromRGB(134, 168, 191)
template.Amount.TextColor3 = Color3.fromRGB(134, 168, 191)
template.PlayerName.TextColor3 = Color3.fromRGB(134, 168, 191)
elseif Rank == 3 then
template.Rank.TextColor3 = Color3.fromRGB(162, 113, 113)
template.Amount.TextColor3 = Color3.fromRGB(162, 113, 113)
template.PlayerName.TextColor3 = Color3.fromRGB(162, 113, 113)
elseif Rank <= 3 then
template.Rank.TextColor3 = Color3.fromRGB(255, 255, 255)
template.Amount.TextColor3 = Color3.fromRGB(255, 255, 255)
template.PlayerName.TextColor3 = Color3.fromRGB(255, 255, 255)
end
end
template.Rank.Text = "#" .. Rank
template.LayoutOrder = Rank
template.Parent = leaderboard.MainPart.SurfaceGui.Scroll
end
end
local foundPlayer = Players:FindFirstChild(isRanked1)
if (foundPlayer) then
local playerData = foundPlayer:FindFirstChild("PlayerData")
if (playerData) then
playerData:WaitForChild("Extra").LeaderboardRank.Value = 1
end
end
for _, player in ipairs(Players:GetPlayers()) do
local playerData = player:FindFirstChild("PlayerData")
if (playerData) then
if (isRanked1 ~= player.Name) then
playerData:WaitForChild("Extra").LeaderboardRank.Value = 0
end
end
end
end)()
end
end
function LeaderboardService:UpdateData()
for i, leaderboard in ipairs(Leaderboards:GetChildren()) do
local dataStoreName = leaderboard.DataStoreName.Value
local leaderboardType = leaderboard.LeaderboardType.Value
local dataStore = DataStoreService:GetOrderedDataStore(dataStoreName)
for _, Player in ipairs(Players:GetPlayers()) do
coroutine.wrap(function()
dataStore:UpdateAsync(Player.UserId, function()
local value = self:GetValue(Player, leaderboardType)
return self:ShortenNumber(value)
end)
end)()
end
end
end
function LeaderboardService:Start()
wait(10)
for i, leaderboard in ipairs(Leaderboards:GetChildren()) do
LayoutUtil.new(leaderboard.MainPart.SurfaceGui.Scroll.UIListLayout)
end
coroutine.wrap(function()
while true do
self:UpdateData()
wait(3)
self:UpdateBoards()
wait(UpdateInterval)
end
end)()
end
return LeaderboardService