Leaderboard Help (Script Not Funcitoning Correctly)

Hey everyone,

So I am making a top donator leaderboard, and it doesn’t seem to function as intended. I have two ServerScripts below that I am currently using. What seems to happen is the datastore in the actual leaderboard (the ordered datastore) isn’t saving data. The player’s username’s aren’t appearing on the board until they are in the server. Let me know if you can help!

Datastore Script: (Parent = ServerScriptService)

local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("DonationsData")

game.Players.PlayerAdded:Connect(function(plr)
	local data = ds:GetAsync(plr.UserId)
	
	if data then
		plr.TotalDonations.Value = data
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	if plr.TotalDonations.Value >= 1 then
		ds:SetAsync(plr.UserId,plr.TotalDonations.Value)
	end
end)

Leaderboard Script: (Parent = DonationLeaderboardPart)

local dss = game:GetService("DataStoreService")
local ds = dss:GetOrderedDataStore("DonationLeaderboardStore")

local leaderboard = script.Parent
local gui = leaderboard.SurfaceGui
local scrollingframe = gui.ScrollingFrame

local Statue = game.Workspace.DonationStatue

local RefreshRate = 60

local function UpdateBoard()
	for i,v in pairs(game.Players:GetPlayers()) do
		if v.TotalDonations then
			ds:SetAsync(v.UserId,v.TotalDonations.Value)
		end
	end

	local success,error = pcall(function()
		local data = ds:GetSortedAsync(false,25)
		local TimePlayedPage = data:GetCurrentPage()

		for rank,saveddata in ipairs(TimePlayedPage) do
			local name = game.Players:GetNameFromUserIdAsync(tonumber(saveddata.key))
			local plr = game.Players:GetPlayerByUserId(saveddata.key)
			local DonationValue = saveddata.value

			if rank == 1 then
				Statue.Humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(saveddata.key))
			end
			
			if rank == 2 then
				game.Workspace.DonationStatue2.Humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(saveddata.key))
			end
			
			if rank == 3 then
				game.Workspace.DonationStatue3.Humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(saveddata.key))
			end

			if DonationValue and DonationValue >= 1 then
				local newLabel = scrollingframe.Template:Clone()
				newLabel.Parent = scrollingframe
				newLabel.Name = name
				newLabel.Visible = true
				
				newLabel.Text = "#"..rank..": ".. plr.Name .." - R$"..DonationValue

				newLabel.Size = UDim2.new(1,0,0.03,0)
			end
		end
	end)
end

while true do
	for i,v in pairs(scrollingframe:GetChildren()) do
		if v.Name == "Template" then
		else
			if v:IsA("TextLabel") then
				v:Destroy()
			end
		end
	end

	UpdateBoard()

	wait(RefreshRate)
end

Thank you in advance!

Hey everyone,

I have looked at the script multiple times, and I still don’t know why it isn’t working. Any help would be appreciated! I waited a few days before trying to post again, but I have still not gotten an answer.

Try putting a print right before the data set async on the leaderboard script, see if it gets that far

I will try and do that, and I will let you know what happens.

It did print right before the SetAsync() statement.

The leaderboard is still looking like this though:

Try wrapping the set async in a pcall and printing the error message, it might tell you something