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

Gear giving script not erroring when a purchase is made?

The script below is not erroring or giving a gear of any sort. I have also printed after the 3rd line and if statement and did not receive a print in either part.

local gear = game:GetService("ServerStorage"):WaitForChild("HyperBike")

game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
	if receiptInfo.ProductId == 966352459 then
		local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
		gear:Clone().Parent = player.Backpack
	end
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

1 answer

Good question!

First of all, make sure that the HyperBike is correct with casing, spelling, etc. Also, make sure it's a tool. It sounds stupid, but sometimes the most common errors get us!

If that doesn't work, try this:

local ServerStorage = game:GetService("ServerStorage")
local Gear = ServerStorage:WaitForChild("HyperBike")
local MPS = game:GetService("MarketplaceService")
local DevProductId = 966352459

MPS.ProcessReceipt = function(receipt)
	local ID = receipt.PlayerId.."-"..receipt.PurchaseId
	local player = game.Players:GetPlayerByUserId(receipt.PlayerId)
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	else
		if receipt.ProductId == DevProductId then
			local clone = Gear:Clone()
			clone.Parent = player.Backpack
		end		
	end
end

11 comments

0

I don't understand why I need to use DataStoreService when the gears are one time purchases. Also that appears to be the exact same as what I had.

0

It's so if a player leaves and rejoins, they still get the reward (that is, if it was not given to them before). This is not the same thing you had. Try it out. It works for me.

0

I would have added gear saving if I wanted it..

0

It doesn't gear save. It's a feature so if a player leaves and somehow the script doesn't go through, they will get the gear in the next play session. This will NOT save the gear. Just try it out. It works for me.

0

It worked the first time I tried it, then after buying again I didn't get it.

0

I edited it without the data store. Not sure why that happened to you. Works just fine with me. Are you using a localscript or a serverscript?

0

server script

0

Alright, well, try my edited message

0

still not working lol i have no clue what the issue is

0

Weird. Not sure. That scripts works for me, and has been for the last year.

0

i have it working in another game, so there must be an issue with the game itself. i have no clue how to fix this.

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