Recently, I’ve started to work on an obby and everything is going perfectly fine in the studio. Today I’ve published the game (still working in progress) for testing. When I tried to skip a stage, it didn’t teleport me to the stage, but it works in studio with no issue.
These are the scripts I’m using:
ServerScriptService:
local skipId = 1912899950
local mps = game:GetService("MarketplaceService")
local checkpoints = workspace:WaitForChild("Checkpoints")
mps.ProcessReceipt = function(info)
local plrId = info.PlayerId
local productId = info.ProductId
local plr = game.Players:GetPlayerByUserId(plrId)
if productId == skipId then
local currentStage = plr.leaderstats.Stage.Value
local nextStage = currentStage + 1
local checkpoint = checkpoints:FindFirstChild(tostring(nextStage))
if checkpoint then
local character = plr.Character
if character then
local targetPosition = checkpoint.Position + Vector3.new(0, 5, 0)
character:SetPrimaryPartCFrame(CFrame.new(targetPosition))
end
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
GUI Button:
local skipId = 1912899950
local mps = game:GetService("MarketplaceService")
local maxStage = #game.Workspace.Checkpoints:GetChildren()
script.Parent.MouseButton1Click:Connect(function()
if game.Players.LocalPlayer.leaderstats.Stage.Value < maxStage then
mps:PromptProductPurchase(game.Players.LocalPlayer,skipId)
end
end)
Is there something I’m missing? If so please let me know.
You’re not updating the leaderstat. You’re simply overriding the variable you’ve defined its value as but not the actual Instance. Also, please make sure the player actually exists in your server either with a player sanity check or using PlaceIdWherePurchased
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productId = 1912899950
local function onProductPurchased(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
warn("Player not found")
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
warn("Leaderstats not found for ", player.Name)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local stage = leaderstats:FindFirstChild("Stage")
if not stage then
warn("Stage not found for ", player.Name)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local currentStage = stage.Value
local nextCheckpoint = workspace.Checkpoints:FindFirstChild(tostring(currentStage + 1))
if nextCheckpoint then
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
player.Character:SetPrimaryPartCFrame(nextCheckpoint.CFrame + Vector3.new(0, 2, 0))
print("Player", player.Name, "teleported to stage", currentStage + 1)
else
warn("Player not found")
end
else
warn("Next checkpoint not found for stage", currentStage + 1)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = onProductPurchased
My main issue here is the developer product not functioning properly, purchase prompt is successful but it doesn’t increase my IntValue or resets my character. Basically nothing happens no matter what script I use.
Make sure no other script is overriding ProcessReceipt callback as that can only be assigned one at a time. You can use the Find All feature to search where else ProcessReceipt occurs.
You would have to merge it together. You can simply move your donation board ProcessReceipt into it’s own module function like so:
-- instead of MarketplaceService.ProcessReceipt = function()
function donationModule.ProcessReceipt(info)
-- your donation board code
end)
And inside your main ProcessReceipt script:
MarketplaceService.ProcessReceipt = function(info)
if info.ProductId == donationId then
return donationModule.ProcessReceipt(info)
elseif info.ProductId == skipId then
-- your skip code
end
end
Ok I’ve realized something else. ProcessReceipt being overridden was apparently not the issue? My brain that doesn’t probably exist is currently in a meltdown. I found out about it when I deleted the donation board and everything about it.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productModule = require(game.ServerScriptService.ProductIds)
local donationModule = require(game.ServerScriptService.DonationModule)
MarketplaceService.ProcessReceipt = function(info)
if info.ProductId == productModule.DonationProductId then
return donationModule.ProcessReceipt(info)
elseif info.ProductId == productModule.SkipProductId then
local player = Players:GetPlayerByUserId(info.PlayerId)
if not player then
warn("Player not found")
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
warn("Leaderstats not found for ", player.Name)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local stage = leaderstats:FindFirstChild("Stage")
if not stage then
warn("Stage not found for ", player.Name)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local currentStage = stage.Value
local nextCheckpoint = workspace.Checkpoints:FindFirstChild(tostring(currentStage + 1))
if nextCheckpoint then
local character = player.Character
if character and character:FindFirstChild("HumanoidRootPart") then
local targetPosition = nextCheckpoint.Position + Vector3.new(0, 5, 0)
character:SetPrimaryPartCFrame(CFrame.new(targetPosition))
print("Player", player.Name, "teleported to stage", currentStage + 1)
else
warn("Character or HumanoidRootPart not found for ", player.Name)
end
else
warn("Next checkpoint not found for stage", currentStage + 1)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
by the way that just fully killed the script (this is getting way too advanced for me now)
Outputs? Assure your code is running by adding a simple print statement after your ProcessReceipt. Are you sure your donation module is not yielding infinitely?