Adding Robux Spent values to leaderstats through purchaseprompts

I want to be able to show how much Robux a user has spent in my game through purchaseprompts. Can someone help me with getting this sorted out thanks

marketplaceSV.PromptPurchaseFinished:Connect(function(player, id, purchased)
	if purchased then
		local purchasesvalue = player:WaitForChild("leaderstats"):WaitForChild("Purchases")

		purchasesvalue.Value += 1
	end
end)
1 Like

if you want to do it with PromptPurchase, you can do:

local marketplaceSV = game:GetService("MarketplaceService")
marketplaceSV.PromptPurchaseFinished:Connect(function(player, id, purchased)
	if purchased then
        local purchasesvalue = player:WaitForChild("leaderstats"):WaitForChild("Purchases")
		purchasesvalue.Value += 1

        local RobuxSpent = nil --Replace with Int / Number Player for the player
        local TypeLookingFor = Enum.InfoType.GamePass --Please Adjust this according to the Type of asset your looking for. Gamepasses and Developer products and subscriptions have different ID systems. 
        local MarketplaceInfo

        local Success, Err = pcall(function()
            MarketplaceInfo = marketplaceSV:GetProductInfo(id, TypeLookingFor)
        end)
    
        if Success then 
           RobuxSpent.Value += MarketplaceInfo.PriceInRobux
        else 
           warn("Failed to get Information!")
	    end


  end
end)

Here is how you can do something like this! Let me know if you have questions or if there are any errors.

Roblox docs on :GetProductInfo() :

Hiya mate I don’t understand this
How will I know what integer to put in, every purchase will be different so I can’t have a specific one. And what is number player for the player? their ID?

everything else seems to be good tho thank you

i think he means replace nil in RobuxSpent with the NumberValue or IntValue that stores how many robux the user spent

As @NGC4637 Said. I meant the int Value that you want to store the value in how total robux. This value with be how much Roblox they spent. So when they bought a product, this value will increase the amount of robux it is.

So when the Product is brought, RobuxSpent is the IntValue that is changing, as we are adding the amount of robux to this value