(UPDATED) Tutorial for making a Marketplace System

Hi everybody! You might already notice that each game has a certain gamepass and premium benefit for a certain or group of certain items.

RobloxScreenShot20220509_184710008

For this topic, I will be showing you how to create a marketplace system for a game.\

Before we begin, always remember to enable the API and third party sales (game-settings>secutity):

Now let’s start off by adding a regular script in ServerScriptService and following these steps:

1. Creating the main variable

You basically have to do one thing here. Before we move on, we will have to assign our main variable.

local mps = game:GetService("MarketplaceService")

The marketplace service tab is where basically, the coding will run on. It is used for prompting purchases and checking if the player owns the gamepass or not.

2. Creating our gamepasses

Now we’re ready to move on to the products were gonna use. Let’s just add three items and do something like this:

-- Change the zeros to your gamepass ID
local Item1 = 0
local Item2 = 0
local Item3 = 0

I chose to name them Item1, Item2, Item3, but you can name it whatever you want!

Now if you don’t know what’s a gamepass ID, then let me explain. Otherwise, you can move on to the next step underneath.

A gamepass ID is the ID for your gamepass. You can find it in the link to your gamepass. For example:
VIP - Roblox” (When you click it, the ID will be the numbers inside the link address.)

3. Adding our tools

We are now at the stage where we add our tools.

To start off, find a tool you want for your gamepass or you can make one yourself. Place your tool in server storage.
Screenshot (9)

Add more tools if needed in server storage. Those tools will be used for our gamepasses. Make sure to rename the tools to prevent random picking (picking a different item if the player owns the gamepass).

4. Checking if the player has the gamepass

We are now at the stage where we check is the player owns the gamepass or not. Here’s what you have to do:

  • Create a function named player:
    game.Players.PlayerAdded:Connect(function(player)
    -- Do stuff
    end)
    
    This is where we check when a player joins the game.
  • Add your conditional statements:
    if mps:UserOwnsGamePassAsync(player.UserID, Item1) then
    -- Do stuff
    end
    
    This is how it looks like when we’re setting what is going to happen when a player owns the gamepass. Now this is what we’re going to do. We’re gonna take the tool we have from the server storage and hand it over to the gamepass owner. Therefore, write the code like this:
    if mps:UserOwnsGamePassAsync(player.UserID, Item1) then
        game.ServerStorage.Tool1:Clone().Parent = player:WaitForChild("Backpack")
        game.ServerStorage.Tool1:Clone().Parent = player:WaitForChild("StarterGear")
    end
    
    How about doing the same thing for the other passes:
     if mps:UserOwnsGamePassAsync(player.UserID, Item2) then
        game.ServerStorage.Tool2:Clone().Parent = player:WaitForChild("Backpack")
        game.ServerStorage.Tool2:Clone().Parent = player:WaitForChild("StarterGear")
    end
     if mps:UserOwnsGamePassAsync(player.UserID, Item3) then
        game.ServerStorage.Tool3:Clone().Parent = player:WaitForChild("Backpack")
        game.ServerStorage.Tool3:Clone().Parent = player:WaitForChild("StarterGear")
    end
    
    So like I said, when the player joins the game with the gamepass owned, they will automatically be given the tool.

=============================================================================

So…voilà! You’re done, meaning your script should officially look like this in the end:

local mps = game:GetService("MarketplaceService")

-- Change the zeros to your gamepass IDs
local Item1 = 0
local Item2 = 0
local Item3 = 0

game.Players.PlayerAdded:Connect(function(player)

  if mps:UserOwnsGamePassAsync(player.UserID, Item1) then
      game.ServerStorage.Tool1:Clone().Parent = player:WaitForChild("Backpack")
      game.ServerStorage.Tool1:Clone().Parent = player:WaitForChild("StarterGear")
  end

 if mps:UserOwnsGamePassAsync(player.UserID, Item2) then
      game.ServerStorage.Tool2:Clone().Parent = player:WaitForChild("Backpack")
      game.ServerStorage.Tool2:Clone().Parent = player:WaitForChild("StarterGear")
  end

   if mps:UserOwnsGamePassAsync(player.UserID, Item3) then
      game.ServerStorage.Tool3:Clone().Parent = player:WaitForChild("Backpack")
      game.ServerStorage.Tool3:Clone().Parent = player:WaitForChild("StarterGear")
  end

end)

Extensions

In case you want to do the thing where it prompts a purchase for the pass, read this section:

You can use parts to prompt a purchase by touching or clicking them.

  • To prompt by touching, just add a script to the part, saying:

    local mps = game:GetService("MarketplaceService")
    
    script.Parent.Touched:Connect(function(Hit)
        local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
        mps:PromptGamePassPurchase(player, 0)
    end)
    
  • To prompt by clicking a part, you could:

    • Add a click detector and a script inside the part that should say:
    local gamepassID = 0 -- Remember to change the zero
    local mps = game:GetService("MarketplaceService")
    
    script.Parent.ClickDetector.MouseClick:Connect(function(Player)
        mps:PromptGamePassPurchase(Player, gamepassID)
    end)
    

    OR

  • Add a proximity prompt and a script inside the part that should say:
    local gamepassID = 0 -- Remember to change the zero
    local mps = game:GetService("MarketplaceService")
    
    script.Parent.ProximityPrompt.Triggered:Connect(function(Player)
        mps:PromptGamePassPurchase(Player, gamepassID)
    end)
    
  • To prompt with button GUIs, just add a local script in the button, saying:
    local mps = game:GetService("MarketplaceService")
    
    local Player = game.Players.LocalPlayer
    
    script.Parent.MouseButton1Click:Connect(function()
        mps:PromptGamePassPurchase(Player, 1)
    end)
    

REMEMBER THIS: Be careful on what you set player as. I made that mistake all the time. As a result, I kept getting an error that said, “player should be of type Player,” which meant that player was only recognized as type “nil”.

Thanks for reading

I hope you enjoyed this topic. If you have any problems, feel free to reply anytime to this topic. :grin:

QUICK REMINDER

This is only my first tutorial I made, so if I leave anything out, feel free to reply to this topic anytime. Again, thanks for reading.

Was this tutorial helpful?
  • Yes it was. Thank you!
  • Nah, I already knew that! :wink:
  • I knew some of it but still helpful. :slight_smile:

0 voters

15 Likes

“player” isnt the function’s name, but a parameter. Remember, those are Anonymous functions. They dont have names.

Other than that, nice tutorial.

5 Likes

My mistake everyone! @Valkyrop is right. I meant to say name the parameter “player”. Thanks @Valkyrop for the correction.

4 Likes

This is a good tutorial for beginners but there are a few things you should consider adding/changing:

1- You don’t use pcalls on your asynchronous functions that make HTTP requests (userownsgamepassasync). If any of those fail because of an HTTP request error, you’re going to have the whole function fail to execute.

2- You don’t use game:GetService() on all your services. If one of your services doesn’t exist for some reason or is renamed, you’re going to run into many errors.

3-

This will error if something that isn’t a player (a character or unanchored part) touches the part because player will be nil. Just check if player is truthy with an if-statement, if it is, prompt the purchase.

7 Likes

Thanks for advice. I will look over and edit this topic.

3 Likes

Learn about using premium for marketplace systems here:
Tutorial for making a premium marketplace system and prompting with modules: Tutorial for making a marketplace system (Prompting with modules)

1 Like