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.
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.
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)
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