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
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.
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
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.
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
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