This script works fine in studio, but not at all in the real game?
This script is a localscript located in the button where you buy the credits
local player = game.Players.LocalPlayer local player2 = game.Players.LocalPlayer.leaderstats function CompletePurchase() wait(1) player.leaderstats.Cash.Value=player.leaderstats.Cash.Value+10 end local MarketplaceService = game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local productId = 23429504 MarketplaceService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == productId then CompletePurchase() end end end local playerProductKey = "plr_" .. receiptInfo.PlayerId .. "_pur_" .. receiptInfo.PurchaseId ds:IncrementAsync(playerProductKey, 1) return Enum.ProductPurchaseDecision.PurchaseGranted end
***I only edited the CompletePurchase function by adding a player argument ***
local DataStore = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local MarketService = game:GetService("MarketplaceService") local productId = 23429504 function CompletePurchase(player) local stats = player:WaitForChild("leaderstats") local cash = stats:WaitForChild("Cash") cash.Value = cash.Value + 10 end MarketService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then local ID,PROD = receiptInfo.PlayerID, receiptInfo.PurchaseId if receiptInfo.ProductId == productId then CompletePurchase(player) end end end local playerProductKey = "plr_" .. ID .. "_pur_" .. PROD DataStore:IncrementAsync(playerProductKey, 1) return Enum.ProductPurchaseDecision.PurchaseGranted end