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

Help with a Gamepass Game-Teleporter?

I'm making a themed-obby game and I can't quite figure out how to create a Gamepass Game-Teleporter. For example, there is a VIP gamepass that gives access to different stages, and there is a teleporter that will teleport them to the other place. I've searched and searched wikis and youtube videos but can't quite find one that works. Would anyone be able to give me a tip?

I have this but I need to create a teleporter script:

local service = game:GetService("GamePassService)
if service:PlayerHasPass(playerObject,passId) then
	print(playerObject.Name.. " owns the pass " ..passId)
end

1 answer

The main way to teleport a player is to set the CFrame of their root part (HumanoidRootPart).

You should now use MarketplaceService instead of GamePassService. Link to the API here: https://developer.roblox.com/api-reference/class/MarketplaceService

In particular, this function will be used in your case: https://developer.roblox.com/en-us/api-reference/function/MarketplaceService/UserOwnsGamePassAsync

You may try this:

local gamepass = -- put your gamepass ID here

local mp = game.MarketplaceService
local players = game.Players

players.PlayerAdded:Connect(function(player)
	if mp:UserOwnsGamePassAsync(player.UserId, gamepass) then
		player.CharacterAdded:Connect(function(character)
			character.HumanoidRootPart.CFrame = CFrame.new() -- teleport them to a chosen CFrame value, for Vector3 values you'd just put the Vector3 in the CFrame.new() constructor.
		end)
	end
end)

What this does is when a player joins, it checks if they own the gamepass using the function I spoke about then create a function attached each them their character is added (when their character loads or respawns for example) to teleport them to a given location marked by a CFrame value.

For tracking after a gamepass purchase prompt, you'd use this: https://developer.roblox.com/api-reference/event/MarketplaceService/PromptGamePassPurchaseFinished

mp.PromptGamePassPurchaseFinished:Connect(function(player, gamepassID, wasPurchased)
	if gamepassID == gamepass and wasPurchased then
		local character = player.Character
		local humanoidRootPart = character.HumanoidRootPart
		humanoidRootPart.CFrame = CFrame.new() -- you can figure this out, it sets position
	end
end)

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