Help on stage skip script

  1. What do you want to achieve? a skip stage

  2. What is the issue? it skip more

  3. What solutions have you tried so far? i ask my scripter and it works bad so i post this

 MarketplaceService = Game:GetService("MarketplaceService")

MarketplaceService.ProcessReceipt = function(receiptInfo)
	players = game.Players:GetPlayers()

	currency = "Stage"

	done = 0

	for i=1,#players do
		if players[i].userId == receiptInfo.PlayerId then
			if receiptInfo.ProductId == 1177543220 and done == 0 then
				done = 1
				players[i].leaderstats[currency].Value = players[i].leaderstats[currency].Value + 1
				players[i].Character.Humanoid.Health = 0
				done = 0
			end
		end
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted	
end

According to this page:
https://developer.roblox.com/en-us/api-reference/callback/MarketplaceService/ProcessReceipt

The receiptInfo is a table with the following keys:

  • PlayerId (number): The user ID of the player that made a purchase
  • PlaceIdWherePurchased (number): The place ID in which a purchase was made
  • PurchaseId (string): A unique identifier for a purchase that ought to be used to prevent granting a > product multiple times
  • ProductId (number): The ID number of the purchased product
  • CurrencyType (Enum.CurrencyType): Deprecated. The type of currency used in the transaction.
  • CurrencySpent (number): The amount of currency spent in the transaction.

Use this API to get the right player without having to search through all the players, remember to not call it too many times. Once is enough(and set it on variable).

Additionally, ProcessReceipt fires on prompt, cancelling and finished. You should use a different event to only detect whether a purchase has completed:

Hello @TheRoblox8978, if your problem has been resolved then ignore this reply. If your problem has not been solved then try to use MarketplaceService.PromptProductPurchaseFinished(), then fire a remote event to a server script and create your skip stage through there. If you do not understand me, continue reading.

First off create a remote event and re-create your local script (buy script):

local DeveloperProduct = 0
local MarketplaceService = game:GetService("MarketplaceService")

MarketplaceService.PromptProductPurchaseFinished:Connect(function(PlayerUserId, PurchasedProductId, Purchased)
	if Purchased == true and PurchasedProductId == DeveloperProduct then
		game.ReplicatedStorage.REMOTEEVENT:FireServer()
	end
end)

Secondly, re-create your server script:

game.ReplicatedStorage.REMOTEEVENT.OnServerEvent:Connect(function(players)

    local currency = "Stage"



            players.leaderstats[currency].Value = players.leaderstats[currency].Value + 1
            local LowerTorso = players.Character.LowerTorso
            LowerTorso.CFrame = --// HERE GOES THE TELEPORT SCRIPT //--



end)

I hope this helped in some sort of way, have an amazing day!