Gamepass won't work

I am making a team changer and I want the “SWAT” team to be locked for a gamepass. Although when I click on it, the gamepass technically initiates, but it tells me there was an error.


Local script inside of the button:

local RemoteEvent = game.ReplicatedStorage.TeamChange

local frame = game.Players.LocalPlayer.PlayerGui:WaitForChild("MainMenu").Frame.TeamsFrame.TeamsLayout
local Player = game.Players.LocalPlayer

local SWATColor = "Navy blue"

local SWATpass = 7844798914

local MarketPlaceService = game:GetService("MarketplaceService")

frame.SWAT.MouseButton1Click:Connect(function()
	if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, SWATpass) then
		print(Player.Name.." owns the SWAT pass")
		RemoteEvent:FireServer(BrickColor.new(SWATColor))
	else
		MarketPlaceService:PromptGamePassPurchase(Player, 7844798914)
		MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, swatPass, wasPurchased)
			if wasPurchased then
				RemoteEvent:FireServer(BrickColor.new(SWATColor))
			else
				print(Player.Name.." declined the SWAT pass purchase.")
				return
			end
		end)
	end
end)

Can anybody help?

1 Like

You might be signed out in Studio or something. Enable 3rd party products too.

2 Likes

I am signed in to studio. I am testing in game. 3rd party products is also enabled.

1 Like

7844798914 is an invalid gamepass ID, is it a developer product you’re trying to sell? If so use:

https://developer.roblox.com/en-us/api-reference/function/MarketplaceService/PromptProductPurchase

1 Like

You were right. Wrong ID :rofl: . I changed it and it works perfectly now! Thank you!

1 Like

https://developer.roblox.com/en-us/api-reference/event/MarketplaceService/PromptProductPurchaseFinished

Here’s the event which is fired when a developer product purchase is finished.

https://developer.roblox.com/en-us/api-reference/function/MarketplaceService/PlayerOwnsAsset

To check if they have a developer product.

2 Likes