Need Help with Script! Dynamic buy currency button not working!

I have a coin that gives me a coin. Pretty simple.

I made a text button that shows the amount of coins you have times 40 (If you have 10 Coins, it will show 400 Coins).

If you click the button, it gives you a dev product you can buy for 24 Robux. If you buy it, I want your Coins to go up by the amount that was on on text label!

Here is what I have:

Script in workspace:

Local Script in the button:

I do not need any scripts. I just need some ideas :slight_smile:

Thanks

-GreenTreeGamingYT

Does the value increase by 50 when it is bought? If so, do the same calculation the local script did on the server and you should be done.

I can do that. But I need the player in order to get the leaderstats.

I canโ€™t get the player in a server script though :\

Alright, so that function is meant for the core process receipt handler. This should work for you in the normal script:

local MPS = game:GetService("MarketplaceService")

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

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

And just the LocalScript like this:

local Player = game:GetService("Players").LocalPlayer
local MPS = game:GetService("MarketplaceService")

Player.leaderstats.Coins.Changed:Connect(functon(NewValue)
    script.Parent.Text = tostring(NewValue.." Taps")
end)

local Id = 1275015820

script.Parent.MouseButton1Click:Connect(function()
    MPS:PromptProductPurchase(Player, Id)
end)

With all that being said, hopefully this is your solution! If this did work for you, I would appreciate it if you marked me as your solution! Have an amazing rest of your day/night! :slightly_smiling_face:

2 Likes

Thanks so much for the script! The scripts didnโ€™t directly work, so I had to do some tweaking. Thanks for the base code though!

My New Scripts:

Normal Script:

local MPS = game:GetService("MarketplaceService")

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

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

Local Script:

local Player = game:GetService("Players").LocalPlayer

local MPS = game:GetService("MarketplaceService")

local function ChangeCurrencyAmount(CurrentTaps: number)

  return math.ceil(CurrentTaps*40)

end

local Amount = ChangeCurrencyAmount(Player:WaitForChild("leaderstats").Coins.Value)

Player.leaderstats.Coins.Changed:Connect(function(NewValue)

  local Amount = ChangeCurrencyAmount(Player:WaitForChild("leaderstats").Coins.Value)

  script.Parent.Text = tostring(Amount.." Taps")

end)

local Id = 1275015820

script.Parent.MouseButton1Click:Connect(function()

  MPS:PromptProductPurchase(Player, Id)

end)

Thanks so much :smiley:

1 Like