Hi!
I need help with my donation leaderboard. If I join it only shows my rank on the leaderboard and it doesn’t show the players from the other ranks, there is an example video:
Ihave tried to fix it, but no errors come out of the output and I can’t see the problem in the script.
This is the main (Module) script:
local datastorservice = game:GetService("DataStoreService")
local donationStore = datastorservice:GetOrderedDataStore("DonationStore9")
local module = {}
task.wait(1)
local function cleanUpLeaderboard(player)
for _, folder in pairs(player.PlayerGui.DonationGUI.Frame.Frame.Frame.ScrollingFrame:GetChildren()) do
if folder:IsA("Frame") then
folder:Destroy()
end
end
module.setUpDonoBoard()
end
local nameCache = {}
local function getPlayerName(playerId)
local nameFromCache = nameCache[playerId]
if nameFromCache then
return nameFromCache
end
local name
local success, _ =pcall(function()
name = game.Players:GetNameFromUserIdAsync(playerId)
end)
if success then
nameCache[playerId] = name
return name
end
return " "
end
function module.setUpDonoBoard()
local isAscending = false
local size = 20
local pages = donationStore:GetSortedAsync(isAscending, size)
local topTwenty = pages:GetCurrentPage()
for rank, data in ipairs(topTwenty) do
local playerId = data["key"]
local amount = data.value
local player = game.Players:GetPlayerByUserId(tonumber(playerId))
local username = getPlayerName(playerId)
local thumbnailType = Enum.ThumbnailType.AvatarBust
local thumbnailSize = Enum.ThumbnailSize.Size420x420
local avatarimg, isready = game.Players:GetUserThumbnailAsync(playerId, thumbnailType, thumbnailSize)
local donoFrame = script.Donator:Clone()
donoFrame.Username.Text = username
donoFrame.Donated.Text = amount
donoFrame.pfp.Image = avatarimg
donoFrame.Rank.Text = "#"..rank
donoFrame.LayoutOrder = rank
for i, Player in game.Players:GetChildren() do
if Player.Name == username then
donoFrame.Parent = Player.PlayerGui.DonationGUI.Frame.Frame.Frame.ScrollingFrame
end
end
end
end
function module.updatePlayerDonoAmount(player, amount)
local success, currentAmount = pcall(function()
return donationStore:GetAsync(player.UserId)
end)
if currentAmount then
currentAmount += amount
else
currentAmount = amount
end
donationStore:SetAsync(player.UserId, currentAmount)
cleanUpLeaderboard(player)
end
return module
This is the (Server) script that sets up the board when the player joins:
local DonationModule = require(script.Parent)
local counter = 0
task.wait(1)
if DonationModule then
print("donationModule found")
DonationModule.setUpDonoBoard()
else
repeat task.wait(1)
print(counter)
counter += 1
until DonationModule
DonationModule.setUpDonoBoard()
end
This is the (Server) script that sets up the board when the player donates:
local MarketplaceService = game:GetService("MarketplaceService")
local DonationModule = require(script.Parent)
local function onProductPromptPurchase(playerId, Id, isPurchased)
local ProductInfo = MarketplaceService:GetProductInfo(Id, Enum.InfoType.Product)
local ProductPrice = ProductInfo.PriceInRobux
local player = game.Players:GetPlayerByUserId(playerId)
if isPurchased then
DonationModule.updatePlayerDonoAmount(player, ProductPrice)
end
end
game:GetService("MarketplaceService").PromptProductPurchaseFinished:Connect(onProductPromptPurchase)
Any help is appreciated!