Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is money giving script increasing the amount givin each time?

This script is supposed to add 1000 gold to you're leaderstats when bought. It works except each time you buy it it gives you more. It is supposed to add 1000 only but every time you buy it it increase like this. 1st time: 1000 2nd: 2000 3rd:3000 4th:4000 etc. Why is it doing this.

-Full Script

--Script in BuyButton part
-- setup local variables
local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 92719865
 
-- 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.Gold.Value = player.leaderstats.Gold.Value + 1000
			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

1 comment

0

You IncrementAsync the key each time the event is called, you should only do this if the gold is added to the players stats.

1 answer

try line 19 this might be the issue it seems like its adding 1000 to the value each time make it go from 1000 to 2000 and so on

 ~~~~~~~~~~~~~~~~~  player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 1000

 

This discussion is preserved as it was. New answers, comments, and votes are closed.