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

Number to add to value multiplying?

I tried to increase a value in a player's leaderstats by 1,000 every time they purchase a developer product, but it keeps multiplying 1,000 by the number of times the product was purchased. (Example: First time buying I would get 1,000, but next time I would get 2,000 instead of 1,000) I expected the script to add 1,000 every time. Here is my ProcessReceipt script (located in ServerScriptService):

local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local mainDataStore = DataStoreService:GetDataStore("MainData")
local function processReceipt(receiptInfo)
  local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
  if not player then
    return Enum.ProductPurchaseDecision.NotProcessedYet
  end
  if receiptInfo.ProductId == 1018802173 then
    player.leaderstats.Coins.Value += 1000
    mainDataStore:SetAsync("Coins_" .. receiptInfo.PlayerId, player.leaderstats.Coins.Value)
    ReplicatedStorage.SendClientMessage:FireClient(player, "The game has been saved!")
  end
  return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt

There are no errors on the server or the client, and I tested on Roblox Studio instead of a live Roblox server so I could use test purchases.

1 answer

You should track how many times they buy it like example(If they bought 1000 for the first time then it would add 1 to the bought count then make it so next time they buy the script does

if player.ProductBuys.Value >= 2 then
    player.leaderstats.Coins.Value += 1000 * ProductBuys.Value
	else
	    player.leaderstats.Coins.Value += 1000
els

Hope this helps I hope I explained the best I can

4 comments

0

Hello, I have a question how this works... Sorry I don't get it why do you have to add 2,000 if the player bought the product more than once?

0

Ahh you can multiply the amount of coins they get by how many boughts they have

0

If this works please accept the answer

0

No that's not what I meant, I mean this was happening and I only wanted it to add 1,000 but it randomly solved itself so it's ok

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