Please help, i’ve wasted 2 hrs doing this code and the leaderboard wont work, but the donos do. I want it to display the highest ranked donator to lowest out of 10. How do I fix these codes?
Location
Devproductpurchase script:
local donationmodule = require(script.Parent)
local function onProductPromptPurchased(playerid, id, isPurchased)
local productInfo = marketplaceService:GetProductInfo(id, Enum.InfoType.Product)
local price = productInfo.PriceInRobux
local player = game.Players:GetPlayerByUserId(playerid)
donationmodule.updatePlayerDonoAmount(player, price)
end
marketplaceService.PromptProductPurchaseFinished:Connect(onProductPromptPurchased)
DonationModule Script
local donationStore = datastoreservice:GetOrderedDataStore("DonationStore")
local startergui = game:GetService("StarterGui")
local module = {}
local function Cleanupleaderboard()
for _,dono in pairs (game.StarterGui.MainMenuGUI.DonationFrame.LeaderBoard.ScrollingFrame:GetChildren()) do
if dono:IsA("Frame") then
dono: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
local usernameframe = startergui.MainMenuGUI.DonationFrame.LeaderBoard.ScrollingFrame.usernameframe
function module.setUpDonoBoard()
local IsAscending = false
local size = 10
local pages = donationStore:GetSortedAsync(IsAscending, size)
local topTen = pages:GetCurrentPage()
for rank, data in pairs(topTen) do
local playerId = data.key
local amount = data.Value
local player = game.Players:GetPlayerByUserId(playerId)
local username = getPlayerName(playerId)
local thumbnailType = Enum.ThumbnailSize.AvatarBust
local thumbnailSize = Enum.ThumbnailSize.Size420x420
local avatarImage, isReady = game.Players:GetUserThumbnailAsync(playerId, thumbnailType, thumbnailSize)
local donoFrame = usernameframe:Clone()
donoFrame.robuxlabel.Text = amount
donoFrame.usernamelabel.Text = username
donoFrame.ImageLabel.Image = avatarImage
donoFrame.Rank = rank
donoFrame.LayoutOrder = rank
donoFrame.Parent = game.StarterGui.MainMenuGUI.DonationFrame.DonoBoard.ScrollingFrame
end
end
function module.updatePlayerDonoAmount(player, amount)
local userId = player.UserId
local success, currentAmount = pcall(function()
return donationStore:GetAsync(userId)
end)
currentAmount += amount
donationStore:SetAsync(userId, currentAmount)
Cleanupleaderboard()
end
return module
setupleaderboard script:
local donationmodule = require(script.Parent)
donationmodule.setUpDonoBoard()
donoscript (working)
local LocalPlayer = game.Players.LocalPlayer
local function promptDonoPurchase(amount)
local devProducts = {
["5"] = 1723983182,
["15"] = 1723983250,
["100"] = 1723983375,
["1000"] = 1723983458,
["10000"] = 1723983592,
}
marketplaceService:PromptProductPurchase(LocalPlayer, devProducts[amount])
end
for _, btn in pairs(script.Parent:GetChildren()) do
if btn:IsA("TextButton") then
btn.MouseButton1Down:Connect(function()
promptDonoPurchase(btn.Name)
end)
end
end
GUI