Hey everyone! What I want to accomplish is to make it where I can have multiple leaderboards in my game without them conflicting with each other. My first leaderboard is based on the cash of other players (Balance Leaderboard) while the other leaderboard is based on player robux donations to the game (Donation Leaderboard).
To describe my issue in an advanced nature, the Balance leaderboard keeps on preventing the Donation Leaderboard from displaying my Top 10 Donators fully (or even at all) onto its SurfaceGui. In addition to this, after my Balance leaderboard loads in the top players, the Donation Leaderboard stops giving me the “remaining time” until it refreshes. Here is a video on what I mean.
robloxapp-20200807-2247080.wmv (661.7 KB)
I tried making separate data stores for each global leaderboard and made sure that my leaderboards don’t have parts that share the same name but it doesn’t seem to fix anything.
Leaderstats:
game.Players.PlayerAdded:connect(function(p)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
stats.Parent = p
local money = Instance.new("IntValue")
money.Name = "Balance" -- Change "Money" to anything you want to name it like "Cash"
money.Value = 0 -- Change the value to how many you want when the player joins the game
money.Parent = stats
local donate = Instance.new("IntValue")
donate.Name = "Donated" -- Change "Money" to anything you want to name it like "Cash"
donate.Value = 0 -- Change the value to how many you want when the player joins the game
donate.Parent = stats
end)
Balance Leaderboard Handler (GlobalLBHandler):
local ds = game:GetService("DataStoreService")
local coinsODS = ds:GetOrderedDataStore("CoinsStats")
local timeUntilReset = 60
while wait(1) do
timeUntilReset = timeUntilReset - 1
script.Parent.Parent.ResetTime.Text = "Resetting in " .. timeUntilReset .. " seconds..."
if timeUntilReset == 0 then
timeUntilReset = 60
for i, plr in pairs(game.Players:GetPlayers()) do
coinsODS:SetAsync(plr.UserId, plr.leaderstats.Balance.Value)
end
for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
if leaderboardRank.ClassName == "Frame" then
leaderboardRank:Destroy()
end
end
local success, errorMsg = pcall(function()
local data = coinsODS:GetSortedAsync(false, 10)
local coinsPage = data:GetCurrentPage()
for rankInLB, dataStored in ipairs(coinsPage) do
local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
local coins = dataStored.value
local template = script.Template:Clone()
template.Name = name .. "Leaderboard"
template.PlrName.Text = name
template.Rank.Text = "#" .. rankInLB
template.Coins.Text = coins
template.Parent = script.Parent
end
end)
end
end
Donation Leaderboard Handler (GlobalLBRHandler):
local ds = game:GetService("DataStoreService")
local coinsODS = ds:GetOrderedDataStore("RobuxStats")
local timeUntilReset = 60
while wait(1) do
timeUntilReset = timeUntilReset - 1
script.Parent.Parent.ResetTimeR.Text = "Resetting in " .. timeUntilReset .. " seconds..."
if timeUntilReset == 0 then
timeUntilReset = 60
for ie, plr in pairs(game.Players:GetPlayers()) do
coinsODS:SetAsync(plr.UserId, plr.leaderstats.Donated.Value)
end
for ie, DonatRank in pairs(script.Parent:GetChildren()) do
if DonatRank.ClassName == "Frame" then
DonatRank:Destroy()
end
end
local success, errorMsg = pcall(function()
local data = coinsODS:GetSortedAsync(false, 10)
local coinsPageR = data:GetCurrentPage()
for robuxs, dataStored in ipairs(coinsPageR) do
local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
local Rbx = dataStored.value
local robux = script.Robux:Clone()
robux.Name = name .. "Leaderboard"
robux.PlrNameR.Text = name
robux.RankR.Text = "#" .. robuxs
robux.CoinsR.Text = Rbx
robux.Parent = script.Parent
end
end)
end
end