I followed a tutorial on the roblox wiki on how to use developer products as I have never worked with them before... It is working and doing what I want it to do... however... If you buy it multiple times (which you should be able to because you are buying in-game currency) the value is added again each time.
For instance:
1st buy: $1000 (the default value) - Total is now $1000
2nd buy: $2000 (added another $1000 to purchase) - Total is now $3000
3rd buy: $3000 (added another $1000) - Total is now $6000
So instead of ending up with $3000 at the end because you bought it 3 times, you end up with $6000. Does that make sense? Okay heres the script what should I fix to prevent this?
-- setup local variables
local MarketplaceService = Game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 36573978
-- define function that will be called when purchase finished
MarketplaceService.ProcessReceipt = function(receiptInfo)
-- find the player based on the PlayerId in receiptInfo
for i, player in ipairs(game.Players:GetChildren()) do
if player.userId == receiptInfo.PlayerId then
-- check which product was purchased
if receiptInfo.ProductId == productId then
-- handle purchase
player.leaderstats.Simoleons.Value = player.leaderstats.Simoleons.Value + 1000
print("success")
end
end
end
-- record the transaction in a Data Store
local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId
ds:IncrementAsync(playerProductKey, 1)
-- tell ROBLOX that we have successfully handled the transaction
return Enum.ProductPurchaseDecision.PurchaseGranted
end
Edit: Leaderboard script:
print("Sim stuff running!")
function onPlayerEntered(newPlayer)
wait(.5)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local stats2 = Instance.new("IntValue")
stats2.Name = "Tycoon"
local cash = Instance.new("IntValue")
cash.Name = "Simoleons"
cash.Value = 10
cash.Parent = stats
stats2.Parent = newPlayer
stats.Parent = newPlayer
end
game.Players.ChildAdded:connect(onPlayerEntered)

4 comments
This is working fine for me when I tested it, have you got any other scripts that could alter the value of Simoleons?
In a blank place its doing the same thing with just the brick, script in starter pack, and my leaderboard script. I will edit the original post to show my leaderboard script can you check and see if it has something to do with that?
Another update: Output says this: Workspace.BuyButton.Script:26: attempt to index upvalue 'ds' (a nil value) Not sure what it means.
After removing the line of code " ds:IncrementAsync(playerProductKey, 1) " It seems to be working, not sure what this means..? Never worked with these before.