I know how to use developer products and all that, but MarketplaceService.ProcessReceipt
just fails to work for no reason. The code is correct, but when I try to test, nothing happens. MarketplaceService:PromptProductPurchase()
works fine, but when I purchase it (in Studio, account not actually charged) and the only action that happens is it prints a blank line even though I didn’t use print()
in my code. It sometimes works but other times it doesn’t. Is this a Roblox error or am I doing something wrong? Does it still charge them if it doesn’t work? Most importantly, does this only occur when you use a DevProduct in your game from another game of yours?
Never had that before.
If you could show us the script and or output that’d be great. I recommend not publishing this version until your issue is resolved, in case players DO get charged.
Yeah, can you show us the code?
local DataStore = game.DataStoreService:GetDataStore("EventDonations")
local alertEvent = game:GetService('ReplicatedStorage'):WaitForChild("Alert")
game.Players.PlayerAdded:Connect(function(player)
local donation = Instance.new("IntValue", player)
donation.Name = "EventDonations"
donation.Value = DataStore:GetAsync(player.UserId) or 0
end)
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
DataStore:SetAsync(player.UserId, player.EventDonations.Value)
end)
end)
game:GetService("MarketplaceService").ProcessReceipt = function(ReceiptInfo)
local Purchasing_Player = game.Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
if ReceiptInfo.ProductId == 1006712442 then -- 10 Robux
if Purchasing_Player then
alertEvent:FireAllClients('Donated', Purchasing_Player.Name, '10')
Purchasing_Player.EventDonations.Value = Purchasing_Player.EventDonations.Value + 10
DataStore:SetAsync(Purchasing_Player.UserId, Purchasing_Player.EventDonations.Value)
end
elseif ReceiptInfo.ProductId == 1006712384 then -- 50 Robux
if Purchasing_Player then
alertEvent:FireAllClients('Donated', Purchasing_Player.Name, '50')
Purchasing_Player.EventDonations.Value = Purchasing_Player.EventDonations.Value + 50
DataStore:SetAsync(Purchasing_Player.UserId, Purchasing_Player.EventDonations.Value)
end
elseif ReceiptInfo.ProductId == 1006712312 then -- 100 Robux
if Purchasing_Player then
alertEvent:FireAllClients('Donated', Purchasing_Player.Name, '100')
Purchasing_Player.EventDonations.Value = Purchasing_Player.EventDonations.Value + 100
DataStore:SetAsync(Purchasing_Player.UserId, Purchasing_Player.EventDonations.Value)
end
elseif ReceiptInfo.ProductId == 1006712228 then -- 500 Robux
if Purchasing_Player then
alertEvent:FireAllClients('Donated', Purchasing_Player.Name, '500')
Purchasing_Player.EventDonations.Value = Purchasing_Player.EventDonations.Value + 500
DataStore:SetAsync(Purchasing_Player.UserId, Purchasing_Player.EventDonations.Value)
end
elseif ReceiptInfo.ProductId == 1007088245 then -- 1000 Robux
if Purchasing_Player then
alertEvent:FireAllClients('Donated', Purchasing_Player.Name, '1000')
Purchasing_Player.EventDonations.Value = Purchasing_Player.EventDonations.Value + 1000
DataStore:SetAsync(Purchasing_Player.UserId, Purchasing_Player.EventDonations.Value)
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
The code is correct. It works but sometimes it fails for no reason and then prints
How can a player buy the product? If it’s by clicking a gui button, can you show me the local script?
game.Workspace.PurchaseFirework.SurfaceGui.ImageButton.Activated:Connect(function()
if not game.Workspace:FindFirstChild("Firework") then
game.MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer, 1006707733)
end
end)
It’s on a SurfaceGui, but it does prompt the purchase every time
The product id is different though, like the product id 1006707733
can’t be found in the script, so are they different products?
it works sometimes, but other times it fails. The product ids are correct and when this bug occurs it just does nothing at all. I’ve even tried debugging and when it doesn’t work it doesn’t even do print()
The script seems fine. Try updating your Roblox Studio or restart it. Sometimes it has some stupid bugs.
Try adding print()
between each line to see when the blank message is printed.
I know this sounds stupid, but most of the time I do this to see where the bug is. Then, I focus on that line.
this happened in studio. For me Roblox and Roblox Studio are up to date
i tried that already. Nothing printed but that one blank line that appeared for no reason
No I meant adding print('Hi')
or anything between each line.
For Example:
workspace:GetChildren():Destroy()
game.ReplicatedStorage:GetChildren():Destroy()
Adding a print()
in between would become:
workspace:GetChildren():Destroy()
print('Hello')
game.ReplicatedStorage:GetChildren():Destroy()
If the Hello
could be printed, then the problem is on the last line. If the Hello
can’t be printed, you only have to focus on the first line.
Then, you can find out which print()
can’t be printed and focus on the line above that print()
.
I did do that type of stuff. Same result happens
Not sure if this is the problem, but in the script where the transaction gets prompted, the product ID is not anywhere in the process script. Could have just been a simple misspell?
Edit: I’ve went ahead to test your scripts in the studio. Upon changing the prompt function to the correct ID, it’s all good.
Lol I said this before, but he said it still works. I don’t know.
there was no error at all. The code was correct for sure. I also accidentally gave you a different dev product. The prompt script also has the rest of the ids.
for i, v in pairs(game.Workspace.DonateOptions:GetChildren()) do
v.SurfaceGui.TextButton.MouseButton1Click:Connect(function()
game.MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer, v.Name)
end)
end
this is not the problem because it prompts the purchase without an error and it always works
I doubt any of these is the result, but at this point everything’s worth a shot.
Try:
- Replace variable “i” with “_”, since you’re using pairs()
- Formatting the Name into a number using tonumber()