Whys my leaderstat value not updating?

MarketplaceService:PromptProductPurchase(PLAYER1, SOME_PRODUCT_ID)

1 Like

Error: ( doesn’t prompt)

‘game:GetService(“MarketplaceService”):PromptProductPurchase(PLAYER2, 16427305037) - Studio
13:20:21.208 MarketplaceService:PromptProductPurchase() player should be of type Player’

I can get my friend to test in 10 minutes so that may just be easier, I’ll let you know if I get any error messages.

1 Like

Ok so I got a few error messages and I added print statements in places so you can see where the script got to:

local function FormatUserGeneratedTShirtsEndpoint(UserId, Cursor)
						Cursor = Cursor or ""
						return "https://catalog.roproxy.com/v1/search/items/details?Category=Clothing&Subcategory=ClassicTShirts&Limit=30&CreatorTargetId="..UserId.."&Cursor="..Cursor
					end
					local function TableConcat(TableA, TableB)
						local TableC = {}
						for i, v in ipairs(TableA) do
							table.insert(TableC, v)
						end
						for i, v in ipairs(TableB) do
							table.insert(TableC, v)
						end
						return TableC
					end
					local function GetUserGeneratedTShirts(UserId, Limit, Cursor)
						local TShirts = {}
						local Endpoint = FormatUserGeneratedTShirtsEndpoint(UserId, Cursor)
						local Success, Result = pcall(function()
							return Http:GetAsync(Endpoint)
						end)
						if not Success then
							warn("Unable to get t-shirts from API: "..Result)
							return TShirts
						end
						local Success2, Result2 = pcall(function()
							return Http:JSONDecode(Result)
						end)
						if not Success2 then
							warn("Unable to decode response from t-shirts API: "..Result2)
							return TShirts
						end
						for _, TShirt in ipairs(Result2.data) do
							table.insert(TShirts, TShirt.id)
						end
						if #TShirts >= Limit then
							return TShirts
						else
							Cursor = Result2.nextPageCursor
							if Cursor then
								local MoreTShirts = GetUserGeneratedTShirts(UserId, Limit, Cursor)
								return TableConcat(TShirts, MoreTShirts)
							else
								return TShirts
							end
						end
					end
					
					local userTShirts = GetUserGeneratedTShirts(winnerId, 10)
					local num = (#userTShirts)
					
					loser.PlayerGui.Donation.Frame.TextLabel.Text = "Donate to ".. winnerName
					
					local table1 = {}
					
					for i = num, 1, -1 do
						local Asset = MarketPlaceService:GetProductInfo(userTShirts[i])
						local assetPrice = Asset.PriceInRobux
						local assetId = Asset.AssetId
						
						if assetPrice == nil or assetId == nil then
							print("Failure")
						else 
							-- Create a new table for each item with the price and id
							local item = {price = assetPrice, id = assetId}

							-- Insert the item into the table
							table.insert(table1, item)
						end

						-- Create a new table for each item with the price and id
						
					end
					
					table.sort(table1, function(a, b)
						return a.price < b.price
					end)

					for i, item in ipairs(table1) do
						if item then
							local price = item.price or "default price"
							local id = item.id or "unknown"
							
							local newButton = workspace.DonateButton:Clone()
							newButton.Name = "DonateButton"..i
							local priceValue = Instance.new("IntValue", newButton)
							priceValue.Name = "Price"
							priceValue.Value = price
							newButton.Text = price .. " R$" 

							local id = Instance.new("IntValue", newButton)
							id.Value = item.id

							newButton.Parent = loser.PlayerGui.Donation.Frame.itemsScroller
							
						else
							
						end
					end
					
					MarketPlaceService.PromptPurchaseFinished:Connect(function(loser, itemId, was_purchased)
						
						print("TWO")
						print(loser.Name)
						print(itemId)
						
						
						if was_purchased then
							
							print("THREE")
							
							local productInfo = MarketPlaceService:GetProductInfo(itemId, Enum.InfoType.Product)
							local itemPrice = productInfo.PriceInRobux

							loser.leaderstats.Donated.Value += itemPrice
							local playerId = loser.UserId

						else
							print("FOUR")
							return
						end
						return
					end)
					
					local function donateButtonClicked(donateButton, loser)

						local itemId = donateButton.Value.Value
						local itemPrice = donateButton.Price.Value
						
						print("ONE")
						print(itemId)
						print(itemPrice)
						
						MarketPlaceService:PromptPurchase(loser, itemId, itemPrice)

						return
					end

					for i,v in pairs(loser.PlayerGui.Donation.Frame.itemsScroller:GetChildren()) do
						if not (v:IsA("TextButton") or v:IsA("ImageButton")) then continue end
						v.MouseButton1Click:Connect(function()
							donateButtonClicked(v, loser)
						end)
					end

I got that same error with player should be type player, I don’t know if it happened every time (I clicked on the button to buy different t shirts a couple times) but it popped up when I clicked the button one of the times.

Edit: I thought u might want to see the local script

local Ms = game:GetService("MarketplaceService")

local button = script.Parent

button.MouseButton1Click:Connect(function()
	
	local player = game.Players.LocalPlayer
	local itemId = button.Value.Value
	local itemPrice = button.Price.Value
	
	Ms:PromptPurchase(player, itemId)
	
	Ms.PromptPurchaseFinished:Connect(function(player, itemId, was_purchased)
		
		if was_purchased then
			
			type creator = {CreatorTargetId: number, CreatorType: string, 
				HasVerifiedBadge: boolean, Id: number, Name: string}

			local function getItemCreator(itemId: number): creator
				local info = Ms:GetProductInfo(itemId)
				return info.Creator
			end
			
			local creator = getItemCreator(itemId)
			local winnerName = creator.Name
			
			local text = "[SYSTEM] "..player.." donated "..itemPrice.." robux to "..winnerName
			game.Workspace.SystemMessage:FireServer(text, itemPrice)
		end

	end)
end)

Actually I’ve managed to get it to a point where its detecting the purchase, however, It worked perfectly the first time, I bought an item that cost 5 and it added 5 to the leaderstat, but now its doubling whatever the actual item price is? Any idea why? (For example I donate 10, it adds 20 to the leaderstat)

local function onPromptPurchaseFinished(player, assetId, isPurchased)
						if isPurchased then
							local asset = MarketPlaceService:GetProductInfo(assetId)
							local leaderstats = player.leaderstats
							local donated = leaderstats.Donated
							donated.Value += asset.PriceInRobux
						else
							print("Not Purchased")
						end
					end

					MarketPlaceService.PromptPurchaseFinished:Connect(onPromptPurchaseFinished)
					
					local function donateButtonClicked(donateButton, loser)
						local itemId = donateButton.Value.Value
						MarketPlaceService:PromptPurchase(loser, itemId)
						return
					end

					for i,v in pairs(loser.PlayerGui.Donation.Frame.itemsScroller:GetChildren()) do
						if not (v:IsA("TextButton") or v:IsA("ImageButton")) then continue end
						v.MouseButton1Click:Connect(function()
							donateButtonClicked(v, loser)
						end)
					end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.