Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't UpdateAsync updating the leaderboard?

Okay so I am trying to incorporate UpdateAsync into my game, trying to follow the wiki but I think I am doing it wrong. I want a player to get 50 coins added to their Coins leaderboard status when they purchase a devproduct. This is the code I have in ServerScriptService to check if the player has purchased the devproduct.

MarketplaceService = game:GetService("MarketplaceService")
local devid = IDHERE


MarketplaceService.ProcessReceipt = function(receiptInfo)
	for i, v in pairs(game.Players:GetChildren()) do	
		if v.userId == receiptInfo.PlayerId then
		if receiptInfo.ProductId == devid then
		local key = "user_" .. v.userId		
		local DataStore = game:GetService("DataStoreService"):GetDataStore("muhcurrency")
		DataStore:UpdateAsync(key, function(oldValue)
		local newValue = oldValue or 0	
		newValue = v.leaderstats.Coins.Value + 50
		return newValue
				end)
			end
		end		
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

I know I am doing something wrong, could someone point it out? Thank You!

1 answer

Hopefully this fixes your problem:

MarketplaceService = game:GetService("MarketplaceService")
local devid = IDHERE -- Whatever this is, it's not supposed to be IDHERE.

MarketplaceService.ProcessReceipt = function(receiptInfo)
    for i, v in pairs(game.Players:GetChildren()) do 
        if v.userId == receiptInfo.PlayerId then
			if receiptInfo.ProductId == devid then
				local key = "user_" .. v.userId     
				local DataStore = game:GetService("DataStoreService"):GetGlobalDataStore("currency")
				DataStore:UpdateAsync(key, function(oldValue)
					return v.leaderstats.Coins.Value + 50
				end
            end
        end
    end
end

2 comments

0

Thank you. I am aware IDHERE is not really supposed to be that, I just put that as like a place holder. I beleive you forgot an ) at the first end so it should be end) so I added that in there. I went into online mode and tested it out....for some odd reason it added 100 coins instead of 50...that is strange, no?

0

Hmmm, that did not seem to fix it sadly. I used to have GetDataStore instead of GetGlobalDataStore. I've noticed that when I joined the server now (I also updated the script that makes the leaderboards to use GetGlobalDataStore) and I noticed that I had 0 currency (when doing just GetDataStore I had more) and when I buy something now, nothing happens at all. Also when leaving the currency does not

This discussion is preserved as it was. New answers, comments, and votes are closed.