so i am making a donation game, and i already made a surface gui where players can click on one of the support buttons and buy devproducts.
well now i want to make another surface gui, but it displays the top ten sponsors, so the people who have given the most robux. i tried to make some code but instead of it putting something on the board nothing happens…
my code:
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local TopsponsorboardPart = game.Workspace.Topsponsorboard:FindFirstChild("Part1")
local Donations = {} -- Table to keep track of donations
-- Function to update the SurfaceGui on the Topsponsorboard part
local function updateSurfaceGui()
if not TopsponsorboardPart then return end
local surfaceGui = TopsponsorboardPart:FindFirstChildOfClass("SurfaceGui")
if not surfaceGui then
surfaceGui = Instance.new("SurfaceGui", TopsponsorboardPart)
surfaceGui.Name = "DonationListGui"
surfaceGui.Adornee = TopsponsorboardPart
surfaceGui.Face = Enum.NormalId.Front
end
local frame = surfaceGui:FindFirstChild("Frame")
if not frame then
frame = Instance.new("Frame", surfaceGui)
frame.Size = UDim2.new(1, 0, 1, 0)
end
frame:ClearAllChildren() -- Clear previous list
local uiListLayout = Instance.new("UIListLayout", frame)
uiListLayout.Padding = UDim.new(0, 5)
uiListLayout.SortOrder = Enum.SortOrder.LayoutOrder
-- Sort the donations table by amount, descending
local sortedDonations = {}
for name, amount in pairs(Donations) do
table.insert(sortedDonations, {name = name, amount = amount})
end
table.sort(sortedDonations, function(a, b) return a.amount > b.amount end)
-- Display top 10 donations
for i = 1, math.min(#sortedDonations, 10) do
local donation = sortedDonations[i]
local textLabel = Instance.new("TextLabel", frame)
textLabel.Size = UDim2.new(1, 0, 0, 20)
textLabel.Text = donation.name .. ": " .. donation.amount .. " Robux"
textLabel.TextColor3 = Color3.new(1, 1, 1)
textLabel.BackgroundTransparency = 1
end
for i = 1, math.min(#sortedDonations, 10) do
local donation = sortedDonations[i]
local textLabel = Instance.new("TextLabel", frame)
textLabel.Text = donation.name .. ": $" .. donation.amount
textLabel.Size = UDim2.new(1, 0, 0, 50)
textLabel.LayoutOrder = i
end
end
-- Function to handle developer product purchases
local function onProductPurchase(player, productId, purchaseId)
-- Assuming you have a way to determine the amount of Robux for each productId
local productAmount = {
-- Example: [productId] = amount
[1837109332] = 5, -- Replace 12345678 with actual product IDs and amounts
-- Add more products as needed
}
local amount = productAmount[productId]
if amount then
if not Donations[player.Name] then
Donations[player.Name] = 0
end
Donations[player.Name] = Donations[player.Name] + amount
updateSurfaceGui()
end
end
MarketplaceService.ProcessReceipt = function(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if player then
onProductPurchase(player, receiptInfo.ProductId, receiptInfo.PurchaseId)
return Enum.ProductPurchaseDecision.PurchaseGranted
else
return Enum.ProductPurchaseDecision.NotProcessedYet
end
end
-- Initial update in case of server restart or script update
updateSurfaceGui()
this is a script in serverScriptService