How To Make That Can Donate on Top Players Leaderboard?

I bad scriptor in global leaderboard. Well, I Need Help.

local statsName = "Coins"
local maxItems = 100
local minValueDisplay = -9.223372e18
local maxValueDisplay = 9.223372e18
local abbreviateValue = false
local updateEvery = 60 
local headingColor = Color3.fromRGB(0, 0, 0)

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard95" .. statsName)
local Frame = script.Parent.Frame
local Contents = Frame.Contents
local Template = script.objTemplate

local COLORS = {
	Default = Color3.fromRGB(255, 255, 255),
	Gold = Color3.fromRGB(255, 204, 51),
	Silver = Color3.fromRGB(204, 204, 204),
	Bronze = Color3.fromRGB(153, 102, 51)
}
local ABBREVIATIONS = { "K", "M", "B", "T" }

local function toHumanReadableNumber(num)
	if num < 1000 then
		return tostring(num)
	end
	
	local digits = math.floor(math.log10(num)) + 1
	local index = math.min(#ABBREVIATIONS, math.floor((digits - 1) / 3))
	local front = num / math.pow(10, index * 3)
	
	return string.format("%i%s+", front, ABBREVIATIONS[index])
end

local function getItems()
	local data = DataStore:GetSortedAsync(false, maxItems, minValueDisplay, maxValueDisplay)
	local topPage = data:GetCurrentPage()

	Contents.Items.Nothing.Visible = #topPage == 0 and true or false

	for position, v in ipairs(topPage) do
		local userId = v.key
		local value = v.value
		local username = "[Not Available]"
		local color = COLORS.Default

		local success, err = pcall(function()
			username = Players:GetNameFromUserIdAsync(userId)
		end)

		if position == 1 then
			color = COLORS.Gold
		elseif position == 2 then
			color = COLORS.Silver
		elseif position == 3 then
			color = COLORS.Bronze
		end

		local item = Template:Clone()
		item.Name = username
		item.LayoutOrder = position
		item.Values.Number.TextColor3 = color
		item.Values.Number.Text = position
		item.Values.Username.Text = username
		item.ProfilePicture.Image = "https://www.roblox.com/bust-thumbnail/image?userId=".. userId .."&width=420&height=420&format=png"
		item.Values.Value.Text = abbreviateValue and toHumanReadableNumber(value) or value
		item.Parent = Contents.Items
	end
end

script.Parent.Parent.Color = headingColor
Frame.Heading.ImageColor3 = headingColor

while true do
	for _, player in pairs(Players:GetPlayers()) do
        local statsValue = player.leaderstats:FindFirstChild(statsName)

		if not statsValue then
			warn("Couldn't find " .. statsName .. " in leaderstats!")
			break
		end

		pcall(function()
			DataStore:UpdateAsync(player.UserId, function()
				return tonumber(statsValue.Value)
			end)
		end)
	end

	for _, item in pairs(Contents.Items:GetChildren()) do
		if item:IsA("Frame") then
			item:Destroy()
		end
	end

	getItems()

	wait()
	Frame.Heading.Heading.Text = statsName .. " Leaderboard"
	wait(updateEvery)
end

robloxapp-20240509-1433301.wmv (1.3 MB)

2 Likes

what are you trying to make? explain it please.

ok so i dont know what you want to do but i tried fixing it

local statsName = "Coins"
local maxItems = 100
local minValueDisplay = -9.223372e18
local maxValueDisplay = 9.223372e18
local abbreviateValue = false
local updateEvery = 60 
local headingColor = Color3.fromRGB(0, 0, 0)

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard95" .. statsName)
local Frame = script.Parent.Frame
local Contents = Frame.Contents
local Template = script.objTemplate

local COLORS = {
	Default = Color3.fromRGB(255, 255, 255),
	Gold = Color3.fromRGB(255, 204, 51),
	Silver = Color3.fromRGB(204, 204, 204),
	Bronze = Color3.fromRGB(153, 102, 51)
}
local ABBREVIATIONS = { "K", "M", "B", "T" }

local function toHumanReadableNumber(num)
	if num < 1000 then
		return tostring(num)
	end
	
	local digits = math.floor(math.log10(num)) + 1
	local index = math.min(#ABBREVIATIONS, math.floor((digits - 1) / 3))
	local front = num / math.pow(10, index * 3)
	
	return string.format("%i%s+", front, ABBREVIATIONS[index])
end

local function getItems()
	local data = DataStore:GetSortedAsync(false, maxItems, minValueDisplay, maxValueDisplay)
	local topPage = data:GetCurrentPage()

	Contents.Items.Nothing.Visible = #topPage == 0

	for position, v in ipairs(topPage) do
		local userId = v.key
		local value = v.value
		local username = "[Not Available]"
		local color = COLORS.Default

		local success, err = pcall(function()
			username = Players:GetNameFromUserIdAsync(userId)
		end)

		if position == 1 then
			color = COLORS.Gold
		elseif position == 2 then
			color = COLORS.Silver
		elseif position == 3 then
			color = COLORS.Bronze
		end

		local item = Template:Clone()
		item.Name = username
		item.LayoutOrder = position
		item.Values.Number.TextColor3 = color
		item.Values.Number.Text = position
		item.Values.Username.Text = username
		item.ProfilePicture.Image = "https://www.roblox.com/bust-thumbnail/image?userId=".. userId .."&width=420&height=420&format=png"
		item.Values.Value.Text = abbreviateValue and toHumanReadableNumber(value) or value
		item.Parent = Contents.Items
	end
end

script.Parent.Parent.Color = headingColor
Frame.Heading.ImageColor3 = headingColor

while true do
	for _, player in pairs(Players:GetPlayers()) do
        local statsValue = player.leaderstats:FindFirstChild(statsName)

		if not statsValue then
			warn("Couldn't find " .. statsName .. " in leaderstats!")
		else
			pcall(function()
				DataStore:UpdateAsync(player.UserId, function()
					return tonumber(statsValue.Value)
				end)
			end)
		end
	end

	for _, item in pairs(Contents.Items:GetChildren()) do
		if item:IsA("Frame") then
			item:Destroy()
		end
	end

	getItems()

	wait(updateEvery)
	Frame.Heading.Heading.Text = statsName .. " Leaderboard"
end

make model of donate to players leaderboard in beast’s rng
here link:
Uncopylocked Game
or make new one?

sorry i dont exactly know what you mean.

look in the scripts and script it and publish
or
make uncopylocked game and copy mines

so hard to make the leaderboard like this. try different ways. or not.

Can you explain what exactly is the issue? You’ve just told us you need help. What particularly doesn’t work?

I think, he has a leaderboard in his game:


It shows everyones Coins leaderstats:
image
I think he wants to be able to donate to the top player, and he doesn’t know how:

Is it a problem with the global leaderboard or getting the passes? You’ve only provided code for the leaderboard.

A couple of things with that script, though:

  • GetSortedAsync needs a pcall
  • You don’t need to use an asset ID link for the player’s icon, you can use Players:GetUserThumbnailAsync with a pcall.

I don’t know don’t ask me ask @Roblox666TheBeast

Oh yeah, oops i didnt look at the name sorry :sweat_smile:
@Roblox666TheBeast please provide the other code and more details

1 Like

need exact script please I bad scripter

What?

I asked if I could see the script that gets the player’s gamepass items. From what I can tell, the leaderboard script works fine.