roblox game passes, badges, consumable products

How to make Roblox Game Passes and badges

Learning how to make Roblox game passes, badges, and consumable products lets players buy fun and exciting items in your game. These items let players gain new abilities and power ups or special items. Badges allow players to show off their gaming skills for others to see. We can use consumable products to create your own currency or reusable items too.

What you’ll learn

  • How to make fun game passes
  • Scripting game passes
  • How to use Roblox data stores
  • Create consumable products

How to setup game passes in Roblox Studio

  • In Roblox Studio, click the settings icon for your game
  • Click Create Game Pass

Game pass icons

When designing your game pass icons make sure it follows these guidelines.

  • Keep your graphics and text simple
  • Make your icons more attractive by using contrasting colors
  • Design should clearly represent what the player has achieved or will gain

Game pass icon technical requirements

  • Supported image formats include jpg, png, gif, tga, and bmp
  • Use a 512×512 template
  • Icons get cropped and trimmed into a circle, avoid adding any details outside the circle

Now you’re ready to upload your icon and configure your game pass.

Here’s a 512×512 template that you can use to get started.

Configure your game pass

Navigate to your published game on Roblox.com and click the settings icon of your game pass. From here you can set the game pass price, in Robux of course. 

Your game pass is now ready to use in game.

How to prompt players to buy game passes

MarketplaceService gives multiple options for players to purchase such as bundles, game passes, Premium, and products. For game passes you’ll use a server script with the PromptGamePassPurchase function. 
Once a player completes their purchase, we’ll then use the PromptGamePassPurchaseFinished event to validate the purchase and then update the player with their new abilities.

Code Example

-- server script
local MarketplaceService = game:GetService("MarketplaceService") 
local gamePassID = 12345
 
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess) 
    if purchaseSuccess == true and purchasedPassID == gamePassID then
    -- update player with game pass ability
  end
end
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
 
-- client script
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local gamePassID = 12345
 
local function promptPurchase() 
    local player = Players.LocalPlayer
    local hasPass = false
 
    local success, message = pcall(function()
      hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
    end)
 
    if not success then
      warn("Error - unable to check if player has pass: " .. tostring(message))
    return
  end 
  if hasPass then
    -- notify player that they already have game pass
  else
    MarketplaceService:PromptGamePassPurchase(player, gamePassID)
  end
end

How to use Roblox game passes in your scripts

Once a game pass is purchased, players do not automatically gain the expected abilities. You must include logic in your scripts for players to use their game pass. You’ll use the MarketplaceService to give players their new abilities that the game pass provides. 

To find your game pass id, browse to it on roblox.com and use the id from the browser url. 

Example

https://www.roblox.com/game-pass/333333/my-awesome-game-pass

Game pass id = 333333


For security reasons we need to use a server script under ServerScriptService and not a client LocalScript when updating player’s with game pass abilities.

Code Example

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players") 
local gamePassID = replace_with_your_game_pass_id
 
local function onPlayerAdded(player) 
  local hasPass = false
  local success, message = pcall(function()
    hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
  end)
 
  if not success then
    warn(message)
    return
  end 
  if hasPass == true then
    -- update player with game pass abilities
  end
end
Players.PlayerAdded:Connect(onPlayerAdded)

How to make Roblox badges

Badges in Roblox are a lot like the achievements you see in other platforms such as Xbox, Playstation, Steam, and so on. Badges are meant for players to show off their gaming skills after accomplishing difficult feats in your game.

Badge setup

It costs 100 robux to create a badge. Similar to how we create a game pass, navigate to your game settings and select the Create Badge option. 

Badges also use icons and have the same technical requirements as game pass icons.

Badge icon technical requirements

  • Supported image formats include jpg, png, gif, tga, and bmp
  • Use a 512×512 template
  • Icons get cropped and trimmed into a circle, avoid adding any details outside the circle

How to give and check player badges

We will use the BadgeService to give or award players their badges. Within a server script, you’ll use the GetBadgeInfoAsync function wrapped in a protected call or pcall function. Once we get the desired badge, your script will use the AwardBadge function to give the player the badge.

Code Example

local BadgeService = game:GetService("BadgeService") 
local function giveBadgeToPlayer(player, badgeId)
  local success, badgeInfo = pcall(function()
    return BadgeService:GetBadgeInfoAsync(badgeId)
  end)
  if success then
    if badgeInfo.IsEnabled then
      local awarded, errorMessage = pcall(function()
        BadgeService:AwardBadge(player.UserId, badgeId)
      end)
      if not awarded then
        warn("Error giving badge:", errorMessage)
      end
    end
  else
    warn("Error while getting badge info")
  end
end

You can give players their badges in several ways. 

For example, if we have a badge for collecting 5 rare items we can include logic in the item’s Touched event function to fire off an event to the data store. In the data store, we’ll check if the player has collected all 5 items and then fire off another event to our game’s Badge Service to award the badge.

Using BindableEvent allows us to keep our logic clean by using the separation of concerns principle. With separation of concerns, each class or service should have a single responsibility. Without separation of concerns, our scripts eventually become a confusing mess.

roblox game pass separation of concerns principle

You can also use badges to allow or deny access to certain areas in your game by using the GetBadgeInfoAsync function.

How to make Roblox developer products

Consumable developer products are used for items that players can buy more than once. For example, a consumable product gets used for in-game currency such as 100 gold bricks for 50 robux. 

Roblox itself does not track how often a player purchases a specific consumable product. All player data that lives for multiple play sessions must store itself in data stores. Within data stores, we can keep player’s purchases to track their inventory and also deduct from it when it’s used. 

To process receipts, we’ll use a Lua table to store functions for each product using the product id as the table key. In each of these functions, we’ll include logic for how this product affects the player.

Once a player successfully completes a purchase, our script will then call these product functions. 

Code Example

local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
 
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
 
local productFunctions = {}
local firstProductId = 12345
productFunctions[firstProductId] = function(receipt, player)
  -- update player with effects gained from purchasing firstProductId
end
 
local function processReceipt(receiptInfo) 
    -- unique product key using player id
    local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
    local purchased = false
    local success, errorMessage = pcall(function()
      purchased = purchaseHistoryStore:GetAsync(playerProductKey)
    end)
    if success and purchased then
      return Enum.ProductPurchaseDecision.PurchaseGranted
    elseif not success then
      error("error:" .. errorMessage)
    end
 
   -- check if player is in game and process receipt when they play again
    local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then
      return Enum.ProductPurchaseDecision.NotProcessedYet
    end	
    local productHandler = productFunctions[receiptInfo.ProductId]
    -- Call the handler function and catch any errors
    local success, result = pcall(productHandler, receiptInfo, player)
    if not success or not result then
      warn("Unable to process product purchase")
      return Enum.ProductPurchaseDecision.NotProcessedYet
    end 
  local success, errorMessage = pcall(function()
    purchaseHistoryStore:SetAsync(playerProductKey, true)
  end)
  if not success then
    error("Error saving purchase data: " .. errorMessage)
  end 
  -- IMPORTANT: Tell Roblox that the game successfully handled the purchase
  return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt

How to prompt for a consumable purchase

To prompt a player for a consumable purchase, your script must use the PromptProductPurchase function. We can trigger this function through any event such as a button press or even when a part is touched.

Code Example

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local productID = 12345
local function promptPurchase()
  local player = Players.LocalPlayer
  MarketplaceService:PromptProductPurchase(player, productID)
end

What’s next

You’ve now learned how to make Roblox game passes, badges, and consumable products. Don’t forget that you must store player consumable purchases in a data store; Roblox will not track this for you. 

Continue your journey by checking out these other Roblox lessons.

Don’t forget to sign up to the newsletter for more content!

Stay curious!

Leave a Reply

%d bloggers like this: