Hello. I have a VIP gamepass in my upcoming game. I want it so that if the player buys or owns the gamepass it calls a remote event that activates the features. How do I do this?
No need to use remote events; just use the UserOwnsGamePassAsync
to check if a player owns the game pass or not, and if they do, enable the feature.
Documentation if you are confused: MarketplaceService | Documentation - Roblox Creator Hub
Ok. I wont use remote events, But how would I make the script though?
What I would do is to make it into a .PlayerAdded
or a .MouseButton1Click
event, and then make an if statement to check if the user owns the requested game pass. If not, I would simply use the return
function to return to the script.
Documentation:
You can do like this:
local mps = game:GetService("MarketPlaceService")
game.Players.PlayerAdded:Connect(function(player)
if mps:UserOwnsGamePassAsync(player.UserId, GamePassID) then
givespecialpower() -- Change it to whatever u want
end
end
where do I insert the gamepass id?
In the second parameter from where the UserOwnsGamePassAsync
function is called in
It has 2 parameters I believe:
- Parameter 1: The Player’s UserID
- Parameter 2: The Gamepass ID, or 00000000 (Which is just a placeholder)
local MarketplaceService = game:GetService("MarketplaceService")
local passId = 00000 -- your gamepass ID
game.Players.PlayerAdded:Connect(function(player)
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, passId) then
print('player owns gamepass!') -- do what you want here
end
end)
In order to check if someone owns a gamepass, you can use MarketplaceService’s UserOwnsGamePassAsync(UserId, GamePassID).
That being said, heres a quick example on how it works:
local MarketplaceService = game:GetService('MarketplaceService')
local Players = game:GetService('Players')
local GamePassID = 000000
local function CheckGamePass(UserId)
return MarketplaceService:UserOwnsGamePassAsync(UserId, GamePassID)
end
local function PlayerAdded(Player)
print(CheckGamePass(Player.UserId)) -- prints true if owned, false if not.
end
local GetPlayers = Players:GetPlayers()
for i = 1, #GetPlayers do
local Player = GetPlayers[i]
PlayerAdded(Player)
end
Players.PlayerAdded:Connect(PlayerAdded)
Add it in the second parameter of the function. If you want to know how to get the gamepass ID, then you can inspect the URL of your gamepass.
- Click on your gamepass
- Check the URL, there should be an 8 digit number.
- Copy that number and paste it in the GamePassID parameter
And done.