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

Teleport to different place on brick touch and has gamepass?

In my game, I am trying to make a 'VIP Door' which will need the player to buy a gamepass so they can teleport to another place. I have put the place in 'Other Places' on the roblox website and put the following code in a script inside the 'Door':

local passId = 622740681 
local marketplaceService = game:GetService("MarketplaceService")
 
function onTouched(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		marketplaceService.PromptPurchaseFinished:connect(function(player,assetId,isPurchased)
			if isPurchased then 
				if assetId == passId then 
					game.GetService("TeleportService"):Teleport(623097807, player)
				end
			end
		end)
	end
end
script.Parent.Touched:connect(onTouched)
	

If you can see, I used some help from the roblox wiki, but I can't get it to work.

2 comments

0

Any errors? If not, put a print("line works") between each line and see where it stops, then I may find the problem.

0

It stops at line 6 (last line where it works). The gamepass isn't on for sale yet. Should put it up for sale?

1 answer

Found a solution!

local passId = 000000000 -- change this to the game pass ID.

function authenticate(player)
	return game:GetService("GamePassService"):PlayerHasPass(player, passId)
end
 
script.Parent.Touched:connect(function(hit)
	if game.Players:FindFirstChild(hit.Parent.Name) then
		if authenticate(game.Players[hit.Parent.Name]) then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			game:GetService("TeleportService"):Teleport(00000000, player) -- Change the 0s to your 'other game' id
		end
	end
end)

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