Hi, I have two developer products in my obby game which allows a player to skip a single stage and one that lets the player skip to the end. Both products work normally, but after the player rebirths(restarts the obby at stage 1) whenever the skip stage is purchased the player skips to the end of the obby instead of skipping a single stage.
Here is my server script where the receipts are processed
local MPS = game:GetService("MarketplaceService")
local skipId = --skip stage Id
local steId = --skip to end Id
MPS.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == skipId then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.Character.HumanoidRootPart.CFrame = game.Workspace.Checkpoints:WaitForChild(tonumber(player.leaderstats.Stage.Value)).CFrame + Vector3.new(0,3,0)
end
if receiptInfo.Id == steId then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.Character.HumanoidRootPart.CFrame = game.Workspace.Checkpoints:FindFirstChild("24").CFrame + Vector3.new(0,3,0)
player.leaderstats.Stage.Value = 25
end
end
Are you setting the player’s stage server-side when they rebirth? I’d recommend using an IntValue to control the stage value.
Also, as @Doomcolp said, it could fail. I’d recommend using the method in the Roblox Creator Documentation, which handles errors. You can find it here, you just need to scroll down a bit.
Yes, the player’s stage is reset server-side when they rebirth. Also I am already using an IntValue for the stage value. I’ll check out the documentation then get back to you. I don’t know if this helps but the stage value is set to 1 at the start of the obby, so when the player purchases the skip stage product, they are teleported to stage 2(which is the 1st checkpoint)
That’s not how .ProcessReciept is supposed to be used. It’s supposed to return a status.
Follow Roblox’s tutorial on it, and you will get this code:
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productFunctions = {}
-- Product ID 123456 skips stage
productFunctions[123456] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local stage = leaderstats and leaderstats:FindFirstChild("Stage")
if stage and stage.Value < 25 then
stage.Value += 1
pcall(player.LoadCharacter, player)
return true
end
end
-- Product ID 456456 skips to the end
productFunctions[456456] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local stage = leaderstats and leaderstats:FindFirstChild("Stage")
if stage and stage.Value ~= 25 then
stage.Value = 25
pcall(player.LoadCharacter, player)
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
-- Get the handler function associated with the developer product ID and attempt to run it
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
-- The user has received their benefits
-- Return "PurchaseGranted" to confirm the transaction
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
-- The user's benefits couldn't be awarded
-- Return "NotProcessedYet" to try again next time the user joins
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Set the callback; this can only be done once by one server-side script
MarketplaceService.ProcessReceipt = processReceipt