Ever wanted to make a way for players to buy in game currency? I have a script that can help you with it!
So, first you will need to create a gui into starter gui, it should look something like this.
So you want to make it a button, once you’ve done that, you want to insert a local script.
The local script can say the same name!
Here’s what you want to put in the script.
MPS = game:GetService("MarketplaceService")
id = 000000000-- replace with your ID
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
MPS:PromptProductPurchase(player, id)
end)
You can add up to as many as you want to, but make sure you replace the 0 with your developer product ID.
Now, since you have that done, you want to insert a script into workspace, and you want this code to be in it! You want to put this in workspace.
local MPS = game:GetService("MarketplaceService")
MPS.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == 0000000 then -- replace with your ID here
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
You can have up to as many as you want! If you want more products for people to buy currency with, you want to duplicate the following
if receiptInfo.ProductId == 0000000 then -- replace with your ID here
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
return Enum.ProductPurchaseDecision.PurchaseGranted
Lastly, make sure you have “Allow third party sales”. If you do not do that, this script will not work for you!
I hope this helped you!
(This is my first time making a post about this topic)
If it isn’t working for you, check the output to see what the error is!