Lesson 2
Passes
Goal: Check pass ownership on the server and grant the perk.
about 6 min3 practice exercises
A pass is bought once and owned for good. Your job in code is to check who owns it and give them the perk.
Do the check on the server when a player joins:
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local VIP_PASS_ID = 0 -- your pass ID from the Creator Dashboard
local function giveVip(player)
player:SetAttribute("VIP", true)
end
Players.PlayerAdded:Connect(function(player)
local ok, owns = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, VIP_PASS_ID)
end)
if ok and owns then
giveVip(player)
end
end)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, passId, purchased)
if purchased and passId == VIP_PASS_ID then
giveVip(player)
end
end)
Two moments matter. The first block handles players who already own the pass when they join. The second handles a player who buys it during this session, so they do not have to rejoin.
The ownership check is a network call, so it is wrapped in pcall.
To sell the pass, a LocalScript calls MarketplaceService:PromptGamePassPurchase(player, VIP_PASS_ID) when the player presses your button. Roblox shows the purchase window. Your code never handles the payment itself.
Pass icons are shown as circles, up to 512 x 512 pixels. Keep anything important away from the corners.
Go deeper on Rodex
Sources
Checked against Roblox's documentation on . The lesson is in our own words; these pages are the source of truth.