How to make a Buy Currency System on Roblox

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!

27 Likes

It should work fine as long as the dev product isn’t from a “third-party” (Belongs to the group/owner or Roblox)

3 Likes

Oh, I thought it didn’t work like that.

1 Like

It’s a good tutorial for really new scripters, however I think its better to put the receiptInfo script in serverscriptservice?

1 Like

@KingJoseon thanks for the advice, but I have already done that in server script service, but it did not work so I put it in workspace

1 Like

It didn’t work? But I thought they both run the same in workspace and serverscriptservice? Thats weird.

I fixed some things and it work thanks :heart:

2 Likes

Your welcome @DapperFoxySWAT , I’m glad I could help!

2 Likes

Shouldn’t this be in #resources:community-tutorials?

1 Like

Try
local MPS = game:GetService(“MarketplaceService”)
local id = 000000000-- replace with your ID
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
MPS:PromptProductPurchase(player, id)
end)

THis is more neat.

This is my first time posting in thsi, so I didn’t know. @zachariapopcorn

Why are MPS and ID not local variables?

1 Like

I got this from a YouTube video, I made it a post because that video was very hard to find so I decided to be nice and give people the script!

I wouldn’t post something that doesn’t use (at the minimum) standard practice. Those variables should be defined as local.

Oh, This is my first time posting in this category so I didn’t know.

I kinda suggest taking down this thread as you said in this post that you got this script from a Youtube video, which means that by posting this in the CR section of the forums, you’re giving readers the sight that you made this script, but in reality you didn’t. This is against rule 17 and can be resulted in a removal from the forums

3 Likes