Problem with MarketplaceService:PromptGamePassPurchase()

Hi,
I have a script which teleports player to VIP room when he have gamepass and teleports back when he don’t have it and gives a prompt but the prompt is not working and it gives this error:
errorLUAU0

Script:

local MarketplaceService = game:GetService("MarketplaceService")
local gamepassID = "0123456789"

script.Parent.Touched:Connect(function(hit)
	if hit:IsA("BasePart") and hit.Parent:FindFirstChild("Humanoid") then
		if MarketplaceService:UserOwnsGamePassAsync(game:GetService("Players"):GetPlayerFromCharacter(hit.Parent).UserId, gamepassID) then
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(0, 31.5, -58)
		else
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(0, 31.5, -46)
			MarketplaceService:PromptGamePassPurchase(game:GetService("Players"):GetPlayerFromCharacter(hit.Parent).UserId, gamepassID)
		end
	end
end)

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

2 Likes

look at it

requires a player instance not a UserId

1 Like

It should be

Marketservice:promptthing(PLAYER INSTANCE,gamepass I'd)

Fixed code:

local MarketplaceService = game:GetService("MarketplaceService")
local gamepassID = "0123456789"

script.Parent.Touched:Connect(function(hit)
	if hit:IsA("BasePart") and hit.Parent:FindFirstChild("Humanoid") then
		if MarketplaceService:UserOwnsGamePassAsync(game:GetService("Players"):GetPlayerFromCharacter(hit.Parent).UserId, gamepassID) then
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(0, 31.5, -58)
		else
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(0, 31.5, -46)
			MarketplaceService:PromptGamePassPurchase(game:GetService("Players"):GetPlayerFromCharacter(hit.Parent), gamepassID)
		end
	end
end)
1 Like
local MPS = game:GetService("MarketplaceService")
local Plrs = game:GetService("Players")
local gamepassId = 0 --change to valid gamepass id
local part = script.Parent

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local char = hit.Parent
		local plr = Plrs:GetPlayerFromCharacter(char)
		if plr then
			local hrp = char:WaitForChild("HumanoidRootPart")
			if MPS:UserOwnsGamePassAsync(plr.UserId, gamepassId) then
				hrp.CFrame = CFrame.new(0, 31.5, -58)
			else
				hrp.CFrame = CFrame.new(0, 31.5, -46)
				MPS:PromptGamePassPurchase(plr, gamepassId)
			end
		end
	end
end)

I’ve cleaned up things, fixed the player instance being used instead of the player’s user ID. Also bare in mind “gamepassId” needs to be an integer, originally you were storing it as a string value.

1 Like