DataStore Problem

Hello, I have a Donation Leaderboard, I have a problem that I can’t fix, when someone donates for the leaderboard they don’t get updated on the leaderboard, it worked before when it was first made and it just stopped working for some reason, I did get saved in the data store and I load up on the leaderboard but whenever I buy a developer product the numbers stay the same even after the leaderboard refresh, it just doesn’t update for some reason and I can’t fix it, API Services are enabled in game settings, any help would be appreciated, here is the part of the script for the leaderboard:

local function refreshLeaderboard()
	-- Clear all frames except Sample
	for _, child in ipairs(PlayerHolder:GetChildren()) do
		if child:IsA("Frame") and child.Name ~= "Sample" then
			child:Destroy()
		end
	end

	local success, data = pcall(function()
		return DonationsDS:GetSortedAsync(false, 10):GetCurrentPage()
	end)

	if not success then
		warn("Failed to get leaderboard data")
		return
	end

	for rank, entry in ipairs(data) do
		local userId = tonumber(entry.key)
		local donated = entry.value

		local username = "Unknown"
		local displayName = "Unknown"
		local thumbUrl = ""

		pcall(function()
			username = Players:GetNameFromUserIdAsync(userId)
		end)
		pcall(function()
			displayName = username -- Roblox does not have GetUserNameFromUserIdAsync, so fallback
		end)
		pcall(function()
			thumbUrl = "https://www.roblox.com/headshot-thumbnail/image?userId="..userId.."&width=48&height=48&format=png"
		end)

		local newFrame = Sample:Clone()
		newFrame.Name = "Player_" .. userId
		newFrame.Visible = true
		newFrame.Parent = PlayerHolder

		local profilePic = newFrame:FindFirstChild("ProfilePicture")
		local displayNameLabel = newFrame:FindFirstChild("DisplayName")
		local nameLabel = newFrame:FindFirstChild("Name")
		local donatedLabel = newFrame:FindFirstChild("Donated")

		if profilePic and profilePic:IsA("ImageLabel") then
			profilePic.Image = thumbUrl
		end
		if displayNameLabel and displayNameLabel:IsA("TextLabel") then
			displayNameLabel.Text = displayName
		end
		if nameLabel and nameLabel:IsA("TextLabel") then
			nameLabel.Text = "@"..username
		end
		if donatedLabel and donatedLabel:IsA("TextLabel") then
			donatedLabel.Text = commaValue(donated) -- NO emojis here
		end

		-- Rainbow effect ONLY for first rank
		if rank == 1 then
			setRigAppearance(StatueCharacter, userId)
			updateStatueOverhead(userId, donated)

			if donatedLabel then
				-- No emoji here for leaderboard donated label but start rainbow effect
				startRainbowEffect(donatedLabel)
			end
		end
	end
end

MarketplaceService.ProcessReceipt = function(receiptInfo)
	local userId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId

	local productDonations = {
		[3365355712] = 5, 
		[3365356166] = 10,   
		[3365356445] = 25,
		[3365356686] = 50,
		[3365356862] = 100,
		[3365357082] = 250,
		[3365357267] = 500,
		[3365357652] = 1000,
		[3365357952] = 5000,
		[3365358193] = 10000,
		[3365358594] = 25000,
		[3365358783] = 50000,
		[3365359225] = 100000,
		[3365359633] = 250000,
		[3365359908] = 500000,
		[3365360294] = 1000000,
	}

	local donationAmount = productDonations[productId]
	if donationAmount then
		local success, currentDonated = pcall(function()
			return DonationsDS:GetAsync(tostring(userId)) or 0
		end)
		if success then
			local newTotal = currentDonated + donationAmount
			pcall(function()
				DonationsDS:SetAsync(tostring(userId), newTotal)
			end)
		end
	end

	-- Refresh leaderboard immediately on purchase
	refreshLeaderboard()

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

while true do
	refreshLeaderboard()
	wait(RefreshTime)
end

Thanks in advance!

1 Like

Oh wow are you not getting any warnings? That’s an EXTREMELY fast update speed. Update at least every 60 seconds if not more.

1 Like

Donation DS is a regular data store not an OrderedDataStore… You cant use that method on regular datastores

1 Like

it is an orderdatastore its just named DonationsDS

I dont get any warnings, and my update speed is 60 seconds?

1 Like

Did you edit your post or did I really read it that wrong? I really thought it said wait() but I guess not.

You should still use task.wait() though

Also, you may not want to refresh it after purchase, as that can also cause issues.


What is your output if you do print(data) before your for rank, entry in data do?

I didnt edit the post, I added task.wait() as u said and removed the refresh after purchase, still doesn’t work just says the same number from before, and the print(data) printed this:

{
[1] = ▼ {
[“key”] = “2752190121”,
[“value”] = 15
}
} - Server - Main:126

Did you have 15 robux donated before updating or after updating? Is it supposed to be 15 robux?

Also, task.wait() wasn’t meant to fix it, it’s just good scripting practice to always use it instead of wait()

its from before when script used to work, and it always shows like that on the leaderboard, if you buy another dev product it doesnt update the value and thats the main problem

Oh it’s data saving issue rather than a leaderboard one… maybe try waiting a bit before updating your leaderboard?

Well, lets go through the standard debugging procedure.

	local donationAmount = productDonations[productId]
	
	print(donationAmount)
	
	if donationAmount then
		local success, currentDonated = pcall(function()
			return DonationsDS:GetAsync(tostring(userId)) or 0
		end)
		
		print(currentDonated)
		
		if success then
			local newTotal = currentDonated + donationAmount
			local success, errorMessage = pcall(function() -- Oh, and make sure to check for errors here too!
				DonationsDS:SetAsync(tostring(userId), newTotal)
			end)
			
			if not success then
				warn("Donate leaderboard failed to set data")
				warn(errorMessage)
			end
		end
	end

What does this print?

1 Like

well idk im so mad that nothing works, been trying to fix it the whole day

got nothing in the output lol, donated 10 robux and nothing

Huh, that’s interesting, looks like the .ProcessReceipt isn’t firing. You’re sure you’re using DevProducts not Gamepasses right?

Hmm, what about a print statement here:

print("Wow what a cool print statement we have here")
MarketplaceService.ProcessReceipt = function(receiptInfo)
...

Does that fire?

Wow what a cool print statement we have here - Server - Main:177, I got that one

Now what happens if you put:

MarketplaceService:ProcessReceipt = function()
	print("Works")
end

in a separate script?

do you have discord it will be easier to talk like that

Yeah, it’s @effbeecee.

I figured out my processReceipt from my other script was messing up with my lb script so I merged them into one and it works, thanks yall for any help