DevProducts work in studio, but not in game

I have a shop where you can buy things in my game. I tested the shop to see if everything worked in Studio and everything was working fine. The problem is, someone playing my game told me they bought one of the DevProducts, but they didn’t get anything. I gave them admin commands as compensation. (I checked to see if they actually bought something, and they did.) My question is, why did the DevProduct only work in studio?

(I am using a free model.)

Here is the script:

-- Down below is an example of a Cash boost

-------------------------------------------------------------------

if productId == 0 then
	local cashmoney = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
		if cashmoney then
			cashmoney.Value = cashmoney.Value + 5000
		end
	-------------------------------------------------------------------

	-- Down below is an example of a Health boost
	
	-------------------------------------------------------------------

	elseif productId == 0 then
	local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
	local char = player.Character
	char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 15
	wait()
	char.Humanoid.Health = char.Humanoid.MaxHealth
	
	-------------------------------------------------------------------

	-- Down below is an example of a WalkSpeed boost

	-------------------------------------------------------------------
	elseif productId == 941791724 then
	local char = player.Character
	if char then
		local human = char:FindFirstChild("Humanoid")
		if human then
			human.WalkSpeed = human.WalkSpeed + 50
		end
	end
	
	elseif productId == 941791747 then
	local char = player.Character
	if char then
		local human = char:FindFirstChild("Humanoid")
		if human then
			human.WalkSpeed = human.WalkSpeed + 150
		end
	end
	-------------------------------------------------------------------
	
	-- Down below is an example of a gear giver
	
	-------------------------------------------------------------------
	
	elseif productId == 0 then
	game.ServerStorage.Sword:Clone().Parent=player.Backpack
	
	elseif productId == 0 then
	game.ServerStorage.Sword2:Clone().Parent=player.Backpack  -- Example if you want to make another gear giver, delete the 2 lines if you dont need it

	-------------------------------------------------------------------
end
return Enum.ProductPurchaseDecision.PurchaseGranted
1 Like

Do you have a function on the Server that validates the authenticity of a purchase and gives the user their purchased item?
Please put in more detail to you’re post, like add the scripts associated with it.

Will do, I kinda rushed while writing it because I have to leave my computer in about 10 min.

Not sure.

You’re not sure? If you’re going to be asking for help on the DevForum, be ready to answer questions we’ll have to help us understand you’re problem.

What Developer Product did they buy?

Server sided, or client sided?

They bought this devproduct:

elseif productId == 941791747 then
local char = player.Character
if char then
local human = char:FindFirstChild(“Humanoid”)
if human then
human.WalkSpeed = human.WalkSpeed + 150
end
end

Server sided.

PostMustBeLongerrrrrrrr

Open the dev console (F9) and view the server log tab. This will have any server side errors there so you can debug. You can additionally use Team Test in Team Create which will actually create a live test server.

This is what is missing from the script:

game.StarterGui.ResetPlayerGuiOnSpawn = false
old_fog = game.Lighting.FogStart
local MarketplaceService = game:GetService(“MarketplaceService”)

function getPlayerFromId(id)
for i,v in pairs(game.Players:GetChildren()) do
if v.userId == id then
return v
end
end
return nil
end

MarketplaceService.ProcessReceipt = function(receiptInfo)
local productId = receiptInfo.ProductId
local playerId = receiptInfo.PlayerId
local player = getPlayerFromId(playerId)
local productName

Will try.

PostMustBeLongerrrrrr

The only errors I see are “Failed to load sound rbxassetid…”

Don’t ever use free models, they are usually outdated or simply don’t work.

The script below was taken from Developer Products - In Game Products.

local MarketplaceService = game:GetService("MarketplaceService")
 
local function processReceipt(receiptInfo)
 
	-- Find the player who made the purchase in the server
	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		-- The player probably left the game
		-- If they come back, the callback will be called again
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
 
	-- Output what product they bought
	print(receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId)

	if receiptInfo.ProductId == Id_Here then
		-- SCRIPT HERE
	end
 
	-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
	return Enum.ProductPurchaseDecision.PurchaseGranted
end
 
-- Set the callback (this can only be done once by one script on the server!)
MarketplaceService.ProcessReceipt = processReceipt

Well you won’t get an error if you’re not testing the product purchasing.

Edit: The resource above is something good to look at as well

Oh yeah let me test buying one…

PostHasToBeLong

I tried buying a product and still no errors. Although this doesn’t matter anyone as the script I currently had was probably just not working.

Thank you. I’ll replace my current script.