roblox
Tutorial page
This article is an intermediate tutorial.
Scripting
This page is a tutorial about Scripting.

In Roblox, Game passes are a huge part of gameplay. In this tutorial, we will go over how to make Game passes give in game bonuses.

We will start by asking ourselves what a Game pass is. A Game pass is something that sells for Robux, can be purchased one time, and can give in-game bonuses.

Required Instances

Not all Instances show in explorer.

Scripting

In this example, we will give a Tool to a player with the Game pass ID of '123'. Open the Script. We are going to start with a simple PlayerAdded method.

--!strict
local Players = game:GetService("Players")

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

end)

Next, we need to define MarketplaceService, the service we will use to check ownership.

--!strict
local MarketplaceService: MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

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

end)

Finally, we will check ownership using an if statement. MarketplaceService has a method just for this purpose, called "UserOwnsGamePassAsync".

--!strict
local MarketplaceService: MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

Players.PlayerAdded:Connect(function(player: Player): ()
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId, 123) then
		local tool = ServerStorage.Tool:Clone()
		tool.Parent = player:WaitForChild("Backpack")
	end
end)

(replace Tool to your preferred tool.)