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

10 comments
DataStores can only be accessed from server scripts.
Alright, where should I put this then?
You would have to either use a server script or use Remote(Events, Functions) to communicate changes from clients to the server
A server script is a regular script correct?
correct
Okay, what about the promptpurchase script should that be local or server?
It doesn't matter whether it's client or server-side, IIRC
The script still isn't working in the server, I check my developer output and this is what I got : "attempt to index field 'local player' a nil value"
Check the answer I posted
Check my comment