Issues with MarketplaceService and PromptPurchase

Hi, So I’m making a GravityCoil Gamepass for my game and I used this script in my “PromptGiver” Mesh

local gamePassId = 129664595 
local db = false

script.Parent.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr and not db then
			if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr, gamePassId) then
				db = true
				local newItem = game.ReplicatedStorage:FindFirstChild("GravityCoil"):Clone()
				newItem.Parent = plr.Backpack
				wait(1)
				db = false
			else
				game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, gamePassId) 
			end
		end
	end
end)

Although I have the GravityCoil in ReplicatedStorage, It reshows the purchaseprompt of the gamepass again and won’t place the grav coil in my backpack? How could I fix this?

Don’t use PlayerOwnsAsset to check for gamepass ownership, use MarketplaceService:UserOwnsGamePassAsync.

local MarketplaceService = game:GetService("MarketplaceService")

if MarketplaceService:UserOwnsGamePassAsync(plr.UserId, gamePassId) then
    -- the rest of your code
end

Using PlayerOwnsAsset is the worst. Try this.

local gamePassId = 129664595 
local db = false

script.Parent.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr and not db then
			if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr, gamePassId) then
				db = true
				local newItem = game.ReplicatedStorage:FindFirstChild("GravityCoil"):Clone()
				newItem.Parent = plr.Backpack
				wait(1)
				db = false
			else
				game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, gamePassId) 
			end
		end
	end
end)

If it doesn’t work, let me know!

This gives me Unable to cast Instance to int64 - Server - Main:9?

type in plr.UserId instead of plr

Appreciate it, It works now! Thanks to everyone who replied

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.