Gamepass Clicker Function Connection Problems

I’m attempting to connect a gamepass to a click function. The idea is that when the function is triggered, the function will check for a gamepass and if the player has it, it will print “Works!”. I’m not quite sure how to get it to work, some help would be appreciated. Thanks.

local MarketplaceService = game:GetService("MarketplaceService")

function phc1() 
    local function phcpassownercheck()
	    if MarketplaceService:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId, 8080398) then
		    print("Works!")
	    end
    end
end

ButtonPHC1.MouseButton1Click:Connect(phc1)

MarketPlaceService on line 5 isn’t capitalized like in your variable.

Also, where is this script? You can’t declare LocalPlayer server-side.

@incapaxx is correct.

@Secretum_Flamma that is not the issue. Identifiers can use any casing anywhere you want.


@BIueMalibu

The problem is you have a nested function inside phc1’s body.

You never called that function, thus making it seem like it doesn’t work.

Remove the outer function while keeping the inner one.

heck, just pass a function literal since this code isn’t really reusable elsewhere.

ButtonPHC1.Activated:Connect(function()
    if MarketplaceService:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId, 8080398) then
        print("Works!")
    end
end)

Notice my use of Activated here. This is the preferred way of listening for UI button input.

1 Like

Sorry about that. Thanks for the clarification.

Still isn’t working, I think the issue may be with

if MarketplaceService:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserId, 8080398) then

I actually typed MarketplaceService in the local but I handwrote that part in the post.

It may be because @incapaxx’s code is using Acivated, it’s looking for a a GUI button. If it’s a physical button, use a click detector.

I did, still no dice.

30characterlimit

I honestly have no idea what’s going on. I did some testing in Studio, and the only error message I found was: UserID is not a valid member of Player.

And the code I was testing with was:

Code
wait(5)
local MarketplaceService = game:GetService("MarketplaceService")

function phc1() 
    local function phcpassownercheck()
	    if MarketplaceService:UserOwnsGamePassAsync(game.Players.Secretum_Flamma.UserId, 8080398) then
		    print("Works!")
	else
		print("NO GAMEPASS")
	    end
    end
end

script.Parent.MouseClick:Connect(phc1)
-- Was testing to see the status of the gamepass. Nothing printed.
while true do
	wait(0.1)
	print(MarketplaceService:UserOwnsGamePassAsync(game.Players.Secreum_Flamma.UserId, 8080398))
end

Turned out I had a SurfaceGui blocking the SurfaceGui I was trying to click on. Deleted it, am inputting code in right now. Will update if it works.

It worked, thank you muchly.

30characterlimit