Making the Price of an Item Increase Every Time it is Bought

I’m trying to make a purchasing system where an item can be purchased multiple times. However every time the player buys the item the price increases by a certain amount. I can’t think of a good way to do this. (This is for in game items). Im having a hard time understanding how to make it client to server and not all client sided.

Thanks for reading

1 Like

Would this be for Dev Products/ Gamepasses, or In-Game items?

Just store the number of times the player has bought the item in a variable or IntValue, and make the price increase with a function like: price = original_price * number_of_times_bought.

You can use Desmos’ Graphing Calculator to find a nice function that increases the price with the number of times the item is bought.
For example, you could do:

local number_of_times_bought = 0
local item_counter = player.ItemCounter
local current_price = 100 -- start off at 100

item_counter.Changed:Connect(function(new_value)
    number_of_times_bought = new_value
end)

function OnPlayerBuy()
    item_counter.Value = item_counter.Value + 1
    current_price = 1.1 * current_price
end
1 Like

Well, with in game items it is fairly easy to do this. It’s a whole different story with Dev Products/Gamepasses.

Anyways, you’re looking to use DataStore for this.

Basically what you want to do is store the original items price in a datastore, and then every time a transaction is verified on the server, you should access said datastore and then increase the price of the item. You can increase it however you would like.

You can also implement a check if you want to prevent the item from exceeding a certain price, so for example:

if item.Price < 5,000 then
    --Store the new price
end

If you’re looking to only change it per server (if you don’t want to save it for the whole game, but instead only want to save the new price for a place instance), you can store the items price in a table, and every time it is bought and the transaction is verified on the server, you can access it in that table and change the price.

And example with a table could be as follows:

local items = {
    ["Gun"] = 100;
}

game.ReplicatedStorage.Transaction.OnServerEvent:Connect(function(client,wantsItem)
    if items[wantsItem] then
        if client.leaderstats.Coins >= items[wantsItem] then
            --Do Stuff
            items[wantsItem] = items[wantsItem] + 50 --you can do whatever you want here
        end
    end
end)
1 Like

If I do it like this, since its all client sided cant it be easily exploited?