RB-004
Roblox game pass check script
Checks if a player owns a game pass and gives them a perk, even right after buying it.
- Script type
- Script
- Where it goes
- ServerScriptService
- Category
- Player data and money
For your own game in Roblox Studio. Not for use in other people's games.
The code
-- Game pass check: gives a faster walk speed to players who own the pass.
local GAME_PASS_ID = 0 -- replace with your game pass ID
local PERK_WALK_SPEED = 24 -- what owners get (the normal speed is 16)
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local function ownsPass(player)
if GAME_PASS_ID == 0 then
return false
end
local ok, result = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAME_PASS_ID)
end)
if not ok then
warn("Could not check the game pass for " .. player.Name .. ": " .. tostring(result))
return false
end
return result
end
local function applyPerk(player)
local character = player.Character
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.WalkSpeed = PERK_WALK_SPEED
end
end
local function onPlayerAdded(player)
local owns = ownsPass(player)
player:SetAttribute("HasPass", owns)
-- Give the perk every time the character spawns.
player.CharacterAdded:Connect(function()
if player:GetAttribute("HasPass") then
applyPerk(player)
end
end)
if owns then
applyPerk(player)
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAdded, player)
end
-- If the player buys the pass while playing, give the perk straight away.
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, passId, wasPurchased)
if wasPurchased and passId == GAME_PASS_ID then
player:SetAttribute("HasPass", true)
applyPerk(player)
end
end)How to set it up
- On the Roblox Creator Dashboard, open your game, then Monetization > Passes, and create a pass. Copy its ID number.
- Paste the ID in place of 0 at GAME_PASS_ID.
- Add the Script to ServerScriptService.
- To let players buy it, call MarketplaceService:PromptGamePassPurchase(player, GAME_PASS_ID) from a button or ProximityPrompt script. Test in Studio: the account that made the game may need to buy it to see the perk.
Change it
- While GAME_PASS_ID is 0 the script does nothing. It will not give the perk to everyone by mistake.
- UserOwnsGamePassAsync talks to Roblox servers and can fail, so it is wrapped in pcall.
- Change applyPerk to give a tool, a chat tag, a bigger jump or anything else your pass promises.
- Check the pass on the server only. A LocalScript check can be faked.
More in Player data and money
- Leaderstats (coins)
- Coin pickup
- Save data with DataStore
- Shop button (RemoteEvent)
- Developer product handler
More Roblox tools
- Shirt and pants templatesFree Roblox clothing templates to download: hoodies, jerseys, jeans, joggers and more.
- Robux tax calculatorWork out what you receive after the marketplace fee, or what to charge.
- Robux to USD calculatorConvert earned Robux to dollars at a DevEx rate you can edit.
- Shirt and pants template makerColour each panel of the 585×559 clothing template and download it.
- Username generatorGenerate usernames that fit the 3–20 character rule.