cách tạo gamepass trong roblox

Passes allow you to lớn charge a one-time Robux fee in order for players to lớn access special privileges within an experience, such as entry to lớn a restricted area, an in-experience avatar item, or a permanent power-up.

Creating Passes

When you're creating an image to lớn use for your Pass, consider the following requirements:

Bạn đang xem: cách tạo gamepass trong roblox

  • Use a template of 512×512 pixels.

  • Save the image in either .jpg, .png, or .bmp format.

  • Don't include important details outside of the circular boundaries because the upload process trims and crops the final badge into a circular image.

To create a new Pass:

  1. Navigate to lớn the Creator Dashboard.

  2. Click on the experience you want to lớn create a Pass for. The experience's Overview page displays.

  3. In the left-hand navigation, select Associated Items. The Associated Items page displays for that specific experience.

  4. In the horizontal navigation, select PASSES. All Passes for that experience display.

  5. Click the CREATE A PASS button. The Create a Pass page displays.

  6. Click the UPLOAD IMAGE button. A tệp tin browser displays.

  7. Select the image you want to lớn display as the icon, then click the Open button.

  8. Fill in the following fields:

    • Name: A title for your Pass.

    • Description: A mô tả tìm kiếm what a player should expect when they purchase the Pass.

  9. Click the CREATE PASS button. The Pass displays within the Passes section of the Associated Items page.

Locating Pass IDs

A Pass ID is the unique identifier of a Pass. You need this ID to lớn assign the Pass a special privilege.

To locate a Pass ID:

  1. Navigate to lớn the Passes section of an experience's Associated Items page.

  2. Hover over a Pass thumbnail and click the button. A contextual thực đơn displays.

  3. Select Copy Asset ID. The Pass ID copies to lớn your clipboard.

Monetizing Passes

After you create a Pass, you can configure its settings to lớn monetize it.

To monetize a Pass:

  1. Navigate to lớn the Passes section of an experience's Associated Items page.

  2. Hover over a Pass thumbnail and click the button. A contextual thực đơn displays.

  3. Select Open in New Tab. The Configure Pass page displays.

  4. In the left-hand navigation, select Sales.

  5. Enable the Item for Sale toggle.

  6. In the Price field, enter the amount of Robux you want to lớn charge players for the Pass. The price you enter affects the amount of Robux you earn per sale.

  7. Click the Save button.

The Pass is now available in the Store tab of your experience's page.

Assigning Pass Privileges

Once a player purchases a Pass, they'll expect to lớn receive the associated special privilege when they play your experience. This does not happen automatically, sánh you must kiểm tra which players own the Pass and assign the special privilege to lớn them.

The following script checks when any player enters the experience, then verifies if that player owns the Pass with the matching ID phối in the variable passID. Place this code in a Script within ServerScriptService sánh the server can handle the special privilege given to lớn the player.


local MarketplaceService = game:GetService("MarketplaceService")

local Players = game:GetService("Players")

local passID = 0000000 -- Change this to lớn your Pass ID

local function onPlayerAdded(player)

local hasPass = false

-- Check if the player already owns the Pass

local success, message = pcall(function()

hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, passID)

end)

-- If there's an error, issue a warning and exit the function

if not success then

Xem thêm: danh gia xiaomi redmi 4x

warn("Error while checking if player has pass: " .. tostring(message))

return

end

if hasPass then

print(player.Name .. " owns the Pass with ID " .. passID)

-- Assign this player the ability or bonus related to lớn the Pass

end

end

-- Connect "PlayerAdded" events to lớn the function

Players.PlayerAdded:Connect(onPlayerAdded)

Prompting In-Experience Purchases

While players can purchase Passes directly from your experience's main page, you can also offer in-experience purchases to lớn players through a cửa hàng or vendor NPC within the experience. Reference the example server-side and client-side scripts for a basic model to lớn prompt players to lớn purchase Passes.

Example Server-Side Script

Place this code in a Script object within ServerScriptService sánh the server can handle the special privilege given to lớn the player.


local MarketplaceService = game:GetService("MarketplaceService")

local passID = 0000000 -- Change this to lớn your Pass ID

-- Function to lớn handle a completed prompt and purchase

local function onPromptPurchaseFinished(player, purchasedPassID, purchaseSuccess)

if purchaseSuccess and purchasedPassID == passID then

print(player.Name .. " purchased the Pass with ID " .. passID)

-- Assign this player the ability or bonus related to lớn the Pass

end

end

-- Connect "PromptGamePassPurchaseFinished" events to lớn the function

MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptPurchaseFinished)

Example Client-Side Script

The following code implements a promptPurchase() function which safely checks if a player has a Pass and prompts them to lớn purchase it if they don't already have it. Place this code in a LocalScript and Call promptPurchase() in situations such as when the player clicks a button or when their character touches a part.


local MarketplaceService = game:GetService("MarketplaceService")

local Players = game:GetService("Players")

local passID = 0000000 -- Change this to lớn your Pass ID

-- Function to lớn prompt purchase of the Pass

local function promptPurchase()

local player = Players.LocalPlayer

local hasPass = false

local success, message = pcall(function()

hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, passID)

end)

if not success then

warn("Error while checking if player has pass: " .. tostring(message))

return

end

if hasPass then

-- Player already owns the Pass; tell them somehow

else

-- Player does NOT own the Pass; prompt them to lớn purchase

Xem thêm: note 7 refurbished xách tay

MarketplaceService:PromptGamePassPurchase(player, passID)

end

end