Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Giving gamepass perk if already have gamepass not working?

So I want to have 1 gamepass button, if you hit it and you don't own the gamepass it will prompt the purchase but if you do already have the gamepass it will give you the gamepass perks. What I've tried so far hasn't worked...

local id = --id will go here

script.Parent.MouseButton1Down:Connect(function()
	if game:GetService("MarketplaceService").PrompGamePassPurchaseFinished:Connect(function(plr,ido,purchase)
		if purchase and id == ido then
			--receiving gamepass perks
		else
			game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, id)
		end
	end)

2 comments

0

You're better off checking on player connect if they own it, and awarding it then.

0

well one thing I immediately notice is that on line 4 you misspelled ".PromptGamePassPurchaseFinished"

2 answers

Your code:

local id = --id will go here

script.Parent.MouseButton1Down:Connect(function()
    if game:GetService("MarketplaceService").PrompGamePassPurchaseFinished:Connect(function(plr,ido,purchase)
        if purchase and id == ido then
            --receiving gamepass perks
        else
            game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, id)
        end
    end)

The problem:

It's small, but should fix the problem, you misspelt PromptGamePassPurchaseFinished (line 4) you have also messed up the end's and added a random if you should also check of they actually bought it, but I'm here to fix what you have given me so here you go:

Fixed code:

local id = --id will go here

script.Parent.MouseButton1Down:Connect(function()
 game:GetService("MarketplaceService").PrompGamePassPurchaseFinished:Connect(function(plr,ido,purchase)
        if purchase and id == ido then
            --receiving gamepass perks
        else
            game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, id)
    end    
end)
    end)

Accept and upvote if this helps! Not working? Comment!

MarketplaceServer:PromptGamePassPurchasedFinished is an event which fires whenever a gamepass prompt has been closed. An event is not what you put into a condition of an if statement.

Don't know what an event is? You've probably seen this before:

local part = script.Parent

local function onTouched(hit)
    print("sOmeBody ToucHa mAh SpAGHeT!!")
end

part.Touched:Connect(onTouched)

You even used the MouseButton1Down event of GuiButtons. Basically events allow functions to "fire" or "happen" when something takes place, such as when a part has been Touched. What you need now isn't an event.

What you are probably looking for is MarketplaceService:UserOwnsGamePassAsync which is a function that returns a boolean (true/false, yes/no). Now you can put this in the condition of an if statement. It's usage would be:

local mps = game:GetService("MarketplaceService")

local playerId = 1234567890 -- player's id to check if own certain game pass
local gamePassId = 0987654321 -- game pass id to check if certain player owns it

if mps:UserOwnsGamePassAsync(playerId, gamePassId) then
    -- give player privileges
else
    -- player doesn't own the game pass :(
end

If I got what you wanted, your entire script would look like this:

local player = game:GetService("Players").LocalPlayer

local mps = game:GetService("MarketplaceService")

local gamePassId = 12345 -- of course use your own

script.Parent.MouseButton1Down:Connect(function()
    -- when the player clicks the button this event will fire
    if mps:UserOwnsGamePassAsync(player.UserId, gamePassId) then
        -- user does own the game pass
    else -- not owned
        mps:PromptGamePassPurchase(player, gamePassId) -- prompt user to buy game pass
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.