How can I make a buy currency system that changes based off of the amount of currency/progress you have in-game?

Hello!

I am wondering how to make a system where you can buy a certain amount of currency (in my case Taps) and it will be added to the amount of Taps you already have.

The catch is that I want the amount of Taps that you get to change based off of the amount of Taps you have upon purchasing.

For example:

If I had 25 Taps, I might have something in the store that gives you 1000 Taps for 25 robux.
If I had 1000 Taps, I might have something in the store that gives you 40000 Taps for 25 robux.

Thanks for the help!

-GreenTreeGamingYT

2 Likes

Not sure if thats a good idea because you would be devalueing your currency. Wont be too much of an issue if you dont allow trading.

What i would do tho is first think of how i want the amount to buy to change with relaation to the currency in pocket. An easy function would be the buy amount is always pocket amount * 2.
Then you could attatch an event for when pocket caah changes. Each time it is changed you update the buy amount.

Thanks!

I am a beginner programmer. It would be great if you could give me an example of the function you were talking about! It does not need to be exact. If I can understand what you mean a little more, I could make the function myself.

My bad by i meant function in the algebraic sense not the programming sense. f(x) = 2x

oh ok.

so you are saying: f(# of taps) = 2(# of taps)

Here is the chunk of code that shows the amount of taps you will get:

local MPS = game:GetService(ā€œMarketplaceServiceā€)

MPS.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == 0000000 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end

I need to try to find a way to implement f(x) = 2x. I cannot just to player.leaderstats.Coins.Value = player.leaderstats.Coins.Value * 2 because that will multiply the amount of Taps you already have by 2 (meaning 150 Taps will become 300 Taps).

Will perhaps making a function that does the arithmetic do the job?

You need to find a way to access and change the buy amount value. I have no experience with in game purchases so i cant really help you there. Seems easy to research though.

Buy amount = f(x) = 2x

ok. Thanks for all of the help!

I’ll make a quick function to determine this for you!

local function ChangeCurrencyAmount(CurrentTaps: number)
    return math.ceil(CurrentTaps*40)
end

local Amount = ChangeCurrencyAmount(Player.leaderstats.Taps.Value) -- Example. Amount will be the returned amount. i.e. 25 taps > 1000 taps. 1000 taps > 4000 taps.
1 Like

I would also add a Taps.Changed:Connect(function()) right?

I would add the local amount in there too

Nope, it will automatically update every time the function is used!

So whenever it runs, it will cache the amount the user has at that time, and do the formula on it!