Help with teleport button

So. I Don’t know if this falls under breaking rules. But. How would i make my script only fire if a user had a certain gamepass?

Here is the script:

script.Parent.MouseButton1Click:Connect(function()
	game.Players.LocalPlayer.character.Torso.CFrame = CFrame.new (2.1, 6.46, 272.15)
end)
1 Like

Use UserOwnsGamePassAsync in an if condition

1 Like

Its because you used local player in a server script

Use :UserOwnsGamepassAsync.

1 Like

Yes. I am not that well at scripting, so this would be relatively easy for most people.

I am not trying to be rude or anything. But, how would that effect the script. The teleport already works fine.

local GamepassId = 0000000

script.Parent.MouseButton1Click:Connect(function()
        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, GamepassId) then
           game.Players.LocalPlayer.character.Torso.CFrame = CFrame.new (2.1, 6.46, 272.15)
        end
end)
1 Like

Alright. I will try that. Thanks for your help!

Here is a working script:
Local script in gui to prompt the purchase:

local Button = script.Parent.TextButton
local GamePassId = 10503628
local MarketPlaceService = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()

MarketPlaceService:PromptGamePassPurchase(Player, GamePassId)
end)

Script inside of part with the click detector:

local MarketPlaceService = game:GetService("MarketplaceService")
local OwnsPass = false
local GamePassId = 10503628

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local success, message = pcall(function()
		OwnsPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamePassId)
	end)
	
	if OwnsPass == true then
		player.Character.HumanoidRootPart.Position = Vector3.new(0,10,0)
	else
		print("You dont have the game pass")
	end
end)

It will teleport you because you own the gamepass, but you can start a local server to see what when you don’t own it

It appears as an error if you don’t include a vector3.new inside the cframe.new.

CFrame doesn’t use Vector3

30charrs

I just copy pasted his original code lol

local Button = script.Parent.TextButton
local GamePassId = 00000
local MarketPlaceService = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()

MarketPlaceService:PromptGamePassPurchase(Player, GamePassId)
end)
local MarketPlaceService = game:GetService("MarketplaceService")
local OwnsPass = false
local GamePassId = 10503628

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local success, message = pcall(function()
		OwnsPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamePassId)
	end)
	
	if OwnsPass == true then
		player.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0,10,0))
	else
		print("You dont have the game pass")
	end
end)

That is a fixed version setting the CFrame of the character.

Using a regular script:

local ClickDetector = script.Parent
local GamepassId = 0
local TeleportLocation = CFrame.new(2.1, 6.46, 272.15)
local PromptPurchaseIfNotOwned = true


ClickDetector.MouseClick:Connect(function(Player)
	if script.ClassName == "LocalScript" then return end
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, GamepassId) then
		local PlayerCharacter = Player.Character or Player.CharacterAdded:Wait()
		if PlayerCharacter then
			if PlayerCharacter:FindFirstChild("HumanoidRootPart") ~= nil then
				PlayerCharacter:FindFirstChild("HumanoidRootPart").CFrame = TeleportLocation
			end
		end
	else
		if PromptPurchaseIfNotOwned then game:GetService("MarketplaceService"):PromptGamePassPurchase(Player, GamepassId) end
	end
end)

If you make the CFrame not use Vector3, it will appear as an error.

You need to do this Part.CFrame = CFrame.new
Position uses Vector3

You should probably test you script before you try to help someone.
10:29:01.283 - Workspace.Part.Script:11: invalid argument #3 (Vector3 expected, got CFrame)

You did it wrong, this is the right way to do it:


local MarketPlaceService = game:GetService("MarketplaceService")
local OwnsPass = false
local GamePassId = 10503628

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local success, message = pcall(function()
		OwnsPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamePassId)
	end)
	
	if OwnsPass == true then
		player.Character.HumanoidRootPart.CFrame = CFrame.new(0,10,01)
	else
		print("You dont have the game pass")
	end
end)local MarketPlaceService = game:GetService("MarketplaceService")
local OwnsPass = false
local GamePassId = 10503628

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local success, message = pcall(function()
		OwnsPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamePassId)
	end)
	
	if OwnsPass == true then
		player.Character.HumanoidRootPart.CFrame = CFrame.new(0,10,01)
	else
		print("You dont have the game pass")
	end
end)

My bad, forgot to change the position to CFrame.

1 Like

No worries, also, you must not use Vector3 in CFrame.
Edit: Nevermind it works

Last time I tried without it, it gave an error. Unless studio updated to fix it, you still need to use it.