My dev-product script only works in studio. I have no clue why and this shouldn’t happen.
I have no errors aswell.
Code:
local Players = game:GetService("Players")
local Marketplace = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
Marketplace.ProcessReceipt = function(ReceiptInfo)
local ProductId = ReceiptInfo.ProductId
local PlayerId = ReceiptInfo.PlayerId
local Player = Players:GetPlayerByUserId(PlayerId)
if Player then
if ProductId == 1259816121 then
local Points = 100
Player.leaderstats.Money.Value += Points
ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
elseif ProductId == 1259816120 then
local Points = 500
Player.leaderstats.Money.Value += Points
ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
elseif ProductId == 1259816390 then
local Points = 1000
Player.leaderstats.Money.Value += Points
ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
elseif ProductId == 1259816391 then
local Points = 2500
Player.leaderstats.Money.Value += Points
ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
I tried some new code, however it also doesn’t work.
Code:
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local function processReceipt(receiptInfo)
-- Find the player who made the purchase in the server
local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
local Player = player
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
print(receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId)
if receiptInfo.ProductId == 1259816121 then
local Points = 100
Player.leaderstats.Money.Value += Points
ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
elseif receiptInfo.ProductId == 1259816120 then
local Points = 500
Player.leaderstats.Money.Value += Points
ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
elseif receiptInfo.ProductId == 1259816390 then
local Points = 1000
Player.leaderstats.Money.Value += Points
ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
elseif receiptInfo.ProductId == 1259816391 then
local Points = 2500
Player.leaderstats.Money.Value += Points
ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt
I’m so confused about this.
Edit: and yes, the print statement does not print in game.
local Players = game:GetService("Players")
local Marketplace = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
Marketplace.ProcessReceipt = function(ReceiptInfo)
local ProductId = ReceiptInfo.ProductId
local PlayerId = ReceiptInfo.PlayerId
local Player = Players:GetPlayerByUserId(PlayerId)
if Player then
if ProductId == 1259816121 then
local Points = 100
Player.leaderstats.Money.Value += Points
ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
elseif ProductId == 1259816120 then
local Points = 500
Player.leaderstats.Money.Value += Points
ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
elseif ProductId == 1259816390 then
local Points = 1000
Player.leaderstats.Money.Value += Points
ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
elseif ProductId == 1259816391 then
local Points = 2500
Player.leaderstats.Money.Value += Points
ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif not Player then
warn("Player is not ready yet.")
return Enum.ProductPurchaseDecision.NotProcessedYet
end
end
local Mark = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer
script.Parent.Activated:Connect(function()
Mark:PromptProductPurchase(Player, script.Parent.Id.Value)
end)
This is in a localscript and it is inside the surface gui in startergui.
You first off should be utilizing the documentation here, which will get you the wanted result. Because this is returning nothing, (true, false, PurchaseGranted, NotProcessedYet, etc…), it won’t work as intended in-studio, nor in-game.