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.
I may have accidently misspelled some functions.
Developer articles:
https://developer.roblox.com/en-us/api-reference/class/TeleportService
Do you mind explaining more, please? I apologize but I’m not a really good scripter
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, if they dont, beg em to buy it.
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
I currently need to leave, so if you need anything else, just ping me.
Thank you very much for this I appreciate it!
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)
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