Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Number to add to value multiplying?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

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? MacaylaMarvelous81 15 — 4y
0
Ahh you can multiply the amount of coins they get by how many boughts they have DuckyRobIox 280 — 4y
0
If this works please accept the answer DuckyRobIox 280 — 4y
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 MacaylaMarvelous81 15 — 4y
Ad

Answer this question