Gamepass script only working in local servers

Hi, so basically I’m working on this new game, I mean experience, and I want to make it where you can type in a valid song ID into a text box and a developer product will prompt to where if you buy it, then whatever ID was in the box it will insert a new sound with that ID into the songs folder. (Sorry for the run-on sentence.)

Anyways, so my problem is that the script that I made only works in local servers. I tried it in single player and in a local server running off of my computer, and they both worked in studio. However, when I tried to use it in team test, the the song wasn’t added to the folder. I still was prompted with the dev product, but I haven’t been able to make it insert the sound itself when I buy it. Any tips?

Here’s the local script:

local MPS = game:GetService("MarketplaceService")
local PlayAudio = RPS:WaitForChild("PlayAudio")
local player = game:GetService("Players").LocalPlayer
local db = false	--cooldown variable

script.Parent.MouseButton1Click:Connect(function()
	if db == false then
		db = true
		local assetID = tonumber(script.Parent.Parent.enterID.Text) --gets the number value of the text box text
		if assetID then
			local success, Info = pcall(MPS.GetProductInfo, MPS, assetID) --checks if the sound id is valid
			if success then
				local sound = Instance.new("Sound", game.Workspace)
				wait(1)
				sound.SoundId = ("rbxassetid://"..assetID)
				wait(1)
				if sound and (sound.TimeLength > 0) then 
					MPS:PromptProductPurchase(player, 1171899953) --prompts the dev product
					PlayAudio:FireServer(assetID)
					sound:Destroy()
				else
					sound:Destroy()
				end
			else
				warn("Invalid song ID!")
			end
		end
		wait(5)
		db = false
	end
end)

Basically it checks whether or not the song ID in the text box is valid and then sends that ID to the server script to insert if you buy the product.

Here is the Server Script:

local MPS = game:GetService("MarketplaceService")
local ISS = game:GetService("InsertService")
local PlayAudio = RPS:WaitForChild("PlayAudio")

PlayAudio.OnServerEvent:Connect(function(player, assetID)
	local function processReceipt(receiptInfo)
		local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
		if not player then
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
		if player then
			local newsound = Instance.new("Sound", game.Workspace.songs) --inserts new sound into the songs folder
			newsound.SoundId = ("rbxassetid://"..assetID)
			newsound.Name = "playerSound"
		end
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end


	MPS.ProcessReceipt = processReceipt
end)

I don’t know why this only works in local servers and not team test or in-game, but I would appreciate any feedback and support. Thanks!

2 Likes

Your issue is that you set MS.ProcessReceipt once remote event is fired. As stated in the Roblox API:

As with all callbacks, this function should be set once and only once by a single Script . If you’re selling multiple products in your game, this callback must handle receipts for all of them.

So to fix your issue, just make a new Server Script that will handle DevProduct purchases. Please read this - MarketplaceService.ProcessReceipt

This site contains an example script, which shows Accurate way to store multiple DevProduct purchases in one script.

1 Like

I tried doing that and now it doesn’t work in team test or single player. I tried copying the script word for word as shown and only changed the product ID for the product function, and it still didn’t do anything. I’m not sure if I’m doing something wrong.

I found out the problem. You were right about having a specific script for handling developer products. So basically, my friend and I are making a game together (I am doing the scripting, and he just adds free models when he feels like it.) So pretty much, he added a donation board into our game because he thought it would be a good idea. Anyways, long story short the donation board has its own script running for developer products to add your name on the leaderboard when you donate. This causes the developer products to act weird because there are two scripts running process receipt. Thank you for helping me understand how developer products work!

1 Like