How to make a Donation Leaderboard

I’ve tried searching Youtube, or the Devforum, but I didn’t see anything that I was looking for.

All the videos, or posts about a Donation Leaderboard are all physical boards, and I want my board to be in the form as a Gui.

Here’s what I got so far:

Purchase Script:

local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local PRODUCT_ID = "ID_PLACEHOLDER"

local button = script.Parent

button.MouseButton1Click:Connect(function(player)
	MPS:PromptProductPurchase(player, PRODUCT_ID)
end)

Explorer:
explorer_screenshot

Screen:

This what I got so far, it all works fine, but the main thing I need help with is the leaderboard. I want it to show the player’s name, and how much they donated.

I know it’s a lot to ask, but I didn’t find anything else that could help me.

(it’s also going to be a single player game, but I still want a leaderboard to show who donated the most)

Any help is appreciated!

2 Likes

You could use code samples from physical leaderboards and apply it to your GUI.

Here’s a tutorial like you mentioned How to make a Top Donators leaderboard

and here’s the relevant update code

local Products = {
	[1338470979] = {
		Name = 'Small';
		Price = 50;
	};
	[1338471308] = {
		Name = 'Big';
		Price = 100;
	};
	[1338471406] = {
		Name = 'Plenty';
		Price = 300;
	};
	[1338471485] = {
		Name = 'Huge';
		Price = 1000;
	};
}

MarketplaceService.PromptProductPurchaseFinished:Connect(function(userId: number, productId: number, purchased: boolean)
	-- get the player by userId
	local player = Players:GetPlayerByUserId(userId)
	
	-- check if the player purchased it or not
	if purchased then
		-- get the price/amount
		local price = Products[productId].Price
		
		-- increment the donator's amount
		pcall(DonatorsDatastore.IncrementAsync, DonatorsDatastore, userId, price)
		
		-- get the cframe to position the emitter
		local position = player.Character.HumanoidRootPart.Position - Vector3.new(0, player.Character.Humanoid.HipHeight, 0)
		local cf = CFrame.new(position)
		
		-- clone and show the emitter
		local clone = script.Emitter:Clone()
		clone:PivotTo(cf)
		clone.Parent = workspace
		
		-- destroy the emitter after 10 seconds
		Debris:AddItem(clone, 10)
	end
end)
1 Like

Hmm, I have a code I wrote for it. I can’t really send right now though. But I’ll tell you what I did.

First, I made IntValue inside each player named “Donated” and saved it inside DataStore
Then I used GetOrderedDataStore() method on it which got all the Values I saved and the UserId’s each value was saved in.
Then I used GetSortedAsync() on it.
Then I looped through it, and duplicated the button.

Sorry, I can only send the whole code tomorrow.

1 Like

I tried to make this work, but first off it’s not what I asked for. I asked for a Gui (in StarterGui, not a Physical board.

Although I was almost able to configure the preexisting script to my liking, unfortunately, I am not skilled enough in that area, I have really never worked with DataStores, etc.

Thank you though!

Ooo! Sounds like a pretty simple idea, is it a Gui in StarterGui?

I can wait, it’s not like I have to do it right now.

Can’t wait to see it!

1 Like

You will have to use data stores, here is another community tutorial on datastores specifically. This one is really good, I reference it often. DataStores - Beginners to Advanced

You aren’t having problems with the GUI, but you can transfer the code from a physical BillboardGUI to a player’s GUI. The relevant parts of creating text labels will be the same.