Donation Leaderboard Not Working?

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
image
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
image
image

1 Like

DataStoreService: StudioAccessToApisNotAlloed: Studio access to APIs is not allowed. API: GetAsync, Data Store: Donation Store

Are you sure your game has access to API services? (Check by going to Game Settings > Security > Enable Studio Access to API Services; if it is green, you have access).

ServerScriptService.DonationModule:78: attempt to perform arithmetic (add) on string and number

You can’t add (use arithmetic on) strings (actually, you can, but only if the strings themselves are numbers like "5" and not things like "hello") and numbers. You might wanna look in to what currentAmount and amount are.

1 Like

Ah okay, you solved the first problem. But for the 2nd, I don’t think the script works when I put currentAMount += amount. This is because the player will donate a certain amount which means data.Value. I need more help with this…

Sorry for the late reply.
Can you do print(currentAmount) and print(amount) to see what they are?

p.s. i’m no expert on this, so i may be heading in the wrong direction :>

Thanks. Nothing happened, so that means amount is probably nil and I don’t know what to do!!!

Did you place the print() functions inside the function module.updatePlayerDonoAmount()?

p.s. i’m no expert on this, so i may be heading in the wrong direction :>

Yep, here it is.


	local userId = player.UserId
	local success, currentAmount = pcall(function()
		return donationStore:GetAsync(userId)
	end)
	print(currentAmount)
	print(amount)
	currentAmount = currentAmount + amount
	
	donationStore:SetAsync(userId, currentAmount)

	Cleanupleaderboard()

end

return module

(Nothing happened)