PromptPurchaseFinished only working for 1 Player

Heya! So I’ve been working on a kit along with Twin (@TwinPlayzDev) and we’ve been wondering about this bug for quite a while going back and forth trying to find the root cause.

I did not find a root cause but I did add a bunch of sanity checks… yet I found out that for some reason this only works when you’re playtesting alone.
Even if you teamtest and buy your own product, it wouldn’t do anything.

Attached code:

local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local AddValueEvent = ReplicatedStorage.Events.AddValue
local ChatEvent = ReplicatedStorage.Events.ChatMsg

MarketplaceService.PromptPurchaseFinished:Connect(function(player, assetId, isPurchased)
	if isPurchased then   
		local data = MarketplaceService:GetProductInfo(assetId, Enum.InfoType.Asset)
		if data then
			if player then
				if player.leaderstats.Donated then
					if tonumber(data.PriceInRobux) then
						player.leaderstats.Donated.Value += tonumber(data.PriceInRobux)
						local DonatedValue = player.leaderstats.Donated.Value
						AddValueEvent:Fire(player.userId, tonumber(data.PriceInRobux), "Donated")
					end
				end
			end


			local GotDonatedName = data.Creator.Name

			local Stands = workspace:FindFirstChild("Stands")
			local StandDescendants = Stands:GetDescendants()

			ChatEvent:FireAllClients(GotDonatedName, player.Name, data.PriceInRobux)

			if game:GetService("Players")[GotDonatedName] then
				local GotDonatedPlr = game:GetService("Players")[GotDonatedName]
				if GotDonatedPlr.leaderstats.Raised then
					if tonumber(data.PriceInRobux) then
						GotDonatedPlr.leaderstats.Raised.Value += tonumber(data.PriceInRobux)
						AddValueEvent:Fire(GotDonatedPlr.userId, tonumber(data.PriceInRobux), "Raised")
						for _, Object in ipairs(StandDescendants) do
							if Object:IsA("TextLabel") and Object.Name == "MoneyRaised" and Object.Parent.Parent.Parent.Parent.Proximity.Owner.Value == GotDonatedName then
								local Amount = GotDonatedPlr.leaderstats.Raised.Value
								Object.Text = Amount .. "$ Raised"
							elseif Object:IsA("ParticleEmitter") and Object.Name == "Money" and Object.Parent.Parent.Proximity.Owner.Value == GotDonatedName then
								Object:Emit(15)
								local Sound = Object.Parent:FindFirstChildOfClass("Sound") 
								Sound:Play()
							end
						end
					end
				end
			end
		end
	end
end)


MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, assetId, isPurchased)
	if isPurchased then   
		local data = MarketplaceService:GetProductInfo(assetId, Enum.InfoType.Asset)
		if data then
			if player then
				if player.leaderstats.Donated then
					if tonumber(data.PriceInRobux) then
					player.leaderstats.Donated.Value += tonumber(data.PriceInRobux)
					local DonatedValue = player.leaderstats.Donated.Value
					AddValueEvent:Fire(player.userId, tonumber(data.PriceInRobux), "Donated")
					end
				end
			end


			local GotDonatedName = data.Creator.Name

			local Stands = workspace:FindFirstChild("Stands")
			local StandDescendants = Stands:GetDescendants()

			ChatEvent:FireAllClients(GotDonatedName, player.Name, data.PriceInRobux)

			if game:GetService("Players")[GotDonatedName] then
				local GotDonatedPlr = game:GetService("Players")[GotDonatedName]
				if GotDonatedPlr.leaderstats.Raised then
					if tonumber(data.PriceInRobux) then
					GotDonatedPlr.leaderstats.Raised.Value += tonumber(data.PriceInRobux)
					AddValueEvent:Fire(GotDonatedPlr.userId, tonumber(data.PriceInRobux), "Raised")
					for _, Object in ipairs(StandDescendants) do
						if Object:IsA("TextLabel") and Object.Name == "MoneyRaised" and Object.Parent.Parent.Parent.Parent.Proximity.Owner.Value == GotDonatedName then
							local Amount = GotDonatedPlr.leaderstats.Raised.Value
							Object.Text = Amount .. "$ Raised"
						elseif Object:IsA("ParticleEmitter") and Object.Name == "Money" and Object.Parent.Parent.Proximity.Owner.Value == GotDonatedName then
							Object:Emit(15)
							local Sound = Object.Parent:FindFirstChildOfClass("Sound") 
							Sound:Play()
							end
						end
					end
				end
			end
		end
	end
end)

Attached place file:
PlsDonateFix v.3.286.rbxl (314,6 KB)

I’ve had quite some reports of issues regarding this code and they all return the same;
ServerScriptService.NewStatsHandler:Line ( this line below ): attempt to perform arithmetic add on number and nil

player.leaderstats.Donated.Value += tonumber(data.PriceInRobux)

Help would be gladly appreciated, thank you!!

1 Like

Bump, help is still needed/appreciated!

Is it a local script?

ServerScript in ServerScriptService, as it’s supposed to be a server-wide effect. Apologies for not specifying!!

The MarketPlaceService.PromptPurchaseFinished uses affiliate gear, so if you’re trying to have an event on developer products purchase, you should use ProcessReceipt here

That’s actually only for developer products.
In our use case we utilize user-made clothing and gamepasses which use the following events:
https://developer.roblox.com/en-us/api-reference/event/MarketplaceService/PromptGamePassPurchaseFinished

Which is public, along with the other event we use for clothing;

https://developer.roblox.com/en-us/api-reference/event/MarketplaceService/PromptPurchaseFinished

Bump again, apologies.
Help is still needed!

Toby and I haven’t found a solution… this is a nifty issue.

Hi!

Please make a print in the top of the PromptPurchaseFinished function, and let me know if it still only prints for 1 player.

Issue resolved. Was a stupid little mistake I made while fetching the data.