How do I make a gamepass-only teleporter within the same game?

So I want to make a part where if you touch it, it teleports you (if you own a specific gamepass) to another part that I named and placed somewhere within the same game, and if you don’t own the gamepass it won’t teleport you, instead, it will show the purchase prompt for the gamepass so that when you purchase it, it will teleport you. How would I make such a thing?

Okay.
Use PlayerOwnsGamepassAsync, to verify if they have the gamepass.
If they dont, use marketplaceservice promptpass purchase.
If playerownsgamepassAsync is true, use Teleport service to teleport them. :smiley:
I may have accidently misspelled some functions.
Developer articles:

https://developer.roblox.com/en-us/api-reference/class/TeleportService

1 Like

Do you mind explaining more, please? I apologize but I’m not a really good scripter :sweat_smile:

1 Like

Sure!
So as an example, (Please don’t copy paste this code)
You could do something like

local MPS = game:GetService("MarketplaceService")
local TS = game:GetService("TeleportService")
-- get your player variable. :D

if MPS:UserOwnsGamePassAsync(player.UserId, gamepassId) == true then
	TS:Teleport(placeId, player)
else
	MPS:PromptGamePassPurchase(player, Gamepassid)
end

You check if player owns the pass, if they do, boot em off, :wink: if they dont, beg em to buy it. :smiley:
You’ll have to handle the touched part yourself, this is just an example code to run if they touch it and then do the prompt/tp

1 Like

I currently need to leave, so if you need anything else, just ping me. :smiley:

1 Like

Thank you very much for this I appreciate it!

1 Like

I think I figured the code out and it seems to be working fine for now, so I’ll post the code here in case someone wants to use it in the future (apologies for the horrible code I’m not a good scripter lol)

Code:

local MS = game:GetService("MarketplaceService")
local Gamepass = 3424234 -- The ID of the Gamepass.
local BuyGUI = true -- Set to false to stop the BuyGUI appearing.
local Whitelist = {
	70068161, 367084597, 30022431, 137437267
} -- USERID || People that can open the door without owning the badge.

-----------------------------------------------------------------------------------------------

local TeleporterAAA = script.Parent -- The teleporter

-----------------------------------------------------------------------------------------------

function CheckWhitelist(v)
	for i = 1, #Whitelist do
		if v == Whitelist[i] then
			return true
		end
	end
	return false
end


script.Parent.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Gamepass <= 0 then return nil end
		if MS:UserOwnsGamePassAsync(plr.UserId, Gamepass) or CheckWhitelist(plr.UserId) then
			if hit and hit.Parent and hit.Parent:FindFirstChild("HumanoidRootPart") then
				hit.Parent.HumanoidRootPart.Position = script.Parent.Parent.TeleporterBBB.Position
			end
		else
			if BuyGUI == true then
				MS:PromptGamePassPurchase(plr, Gamepass)
			end
		end
	end
end)

1 Like

I suggest wrapping the ‘UserOwnsGamePassAsync’ in a pcall.

local success,result = pcall(function()
    return Market:UserOwnsGamepassAsync(PlayerID,GamepassID)
end)

if success then
   if not result then -- if they dont have the pass

   else -- if they have it

   end
end
1 Like