Need Help With Script

Hello Developers!

I am trying to help someone make a few scripts, but we have ran into a problem.

Here is the script:

MarketplaceService = game:GetService("MarketplaceService")
local dataStoreService = game:GetService("DataStoreService")
local saveDataStore = dataStoreService:GetDataStore("---------")

MarketplaceService.ProcessReceipt = function(receiptInfo)
	for _, Player in pairs(game.Players:GetChildren()) do
		if Player.UserId == receiptInfo.PlayerId then
			if receiptInfo.ProductId == 1261045939 then -- Resets Levels
				Player.leaderstats.Stage.Value = 0
				Player.Character.Humanoid.Health = 0
				saveDataStore:SetAsync(Player.UserId, {Stage = 0})
			elseif receiptInfo.ProductId == 1261228261 then	-- Skips Level
				Player.leaderstats.Stage.Value = Player.leaderstats.Stage.Value +1
				Player.Character.Humanoid.Health = 0
				saveDataStore:SetAsync(Player.UserId, {Stage = Player.leaderstats.Stage.Value})
			end
		end
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted	
end

For some reason, only the Skip Level works.

The Ids are right, but the script just does not work, does anyone know what to do because I am not the best at Game Pass Stuff.

Any help wanted, Thank you! Have a good day!

1 Like

Does the first if statement (productId == 12610…etc) actually get fired? As in if I put a print statement there does that work? If so then I know that if the statement is working and that section of code is working the problem lies in the datastore. Otherwise if the if statement isn’t firing its to do with the product ID likely not matching what it is finding.

1 Like

The script inside the script works fine, if you remove the skip, then it works.

Try printing out all the product ids, you may have an issue with having both product ids. (I don’t have experience with products personally as I don’t monetize things)

1 Like

This script works, but for only one player:

MarketplaceService = game:GetService("MarketplaceService")
local dataStoreService = game:GetService("DataStoreService")
local saveDataStore = dataStoreService:GetDataStore("---------")

MarketplaceService.ProcessReceipt = function(receiptInfo)
	for _, Player in pairs(game.Players:GetChildren()) do
		if Player.UserId == receiptInfo.PlayerId then
			if receiptInfo.ProductId == 1261045939 then -- Resets Levels
				Player.leaderstats.Stage.Value = 0
				Player.Character.Humanoid.Health = 0
				saveDataStore:SetAsync(Player.UserId, {Stage = 0})
				
			end
			if receiptInfo.ProductId == 1261228261 then	-- Skips Level
				Player.leaderstats.Stage.Value = Player.leaderstats.Stage.Value +1
				Player.Character.Humanoid.Health = 0
				saveDataStore:SetAsync(Player.UserId, {Stage = Player.leaderstats.Stage.Value})
			end
		end
		return Enum.ProductPurchaseDecision.PurchaseGranted	
	end
end
1 Like

You probably misplaced it, check if it’s misplaced

1 Like

Move this line to right after the data store set

Both of these.

Where the current return is, say return Enum.ProductPurchaseDecision.NotProcessedYet

2 Likes

Same problem. Only works for one player.

Looks like it should work for all players.